We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37946
    • 70 Posts
    Hello!
    I am curious if there is a way I can show/hide a TV input within the manager.

    Example:
    Template name: BaseTemplate
    TV name: MyTV

    Lets say I have 2 pages, both of which use "BaseTemplate". I have given "MyTV" access to "BaseTemplate" when I created the template variable.
    On page "A" I want the user to be able to use "MyTV" (edit/create etc).
    On page "B" - "MyTV" is not applicable to anything that is on the page. So ideally, I'd like to not show it within the manager when the user is editing this specific page. Even though the two pages are using the same template.

    I realize a simple solution would be to just create a new template and go. I'm trying to keep the number of templates down. It seems like there should be a way - I can filter the output on my template...just not sure how to filter the input from within the manager.

    Hope that makes sense. Thank you for your time!
      • 4172
      • 5,888 Posts
      It is the simplest way to have different TVs on different resources by using different templates for them.
      You can reuse the template - code by putting the template-code into chunks or by using static templates which point to the same template-file.
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 37946
        • 70 Posts
        Hi Bruno17!
        I think I follow what you are saying...

        I don't know if I've done a good enough job of explaining what I'm curious about.

        Lets say I have a template called "AnimalTemplate".

        Here is a list of TV's that this template has access to:

        • "TV_animal_name"
        • "TV_animal_breed"
        • "TV_pet_name"

        Lets say I have a page within the manager called "Farm Animals" and another page within the manager called "Pets".
        Both pages use the "AnimalTemplate" as a template.

        I have filters within the template that check which page I am on and will show/hide any markup. This eliminates the need for multiple templates - from an output perspective.

        Lets say I am editing the "Farm Animals" page within the manager. I see the "Template variables" tab, and when I click on it, the only TV options I want to see are:

        • "TV_animal_name"
        • "TV_animal_breed"

        Now lets say I am editing the "Pets" page within the manager. I see the "Template variables" tab, and when I click on it, the only TV options I want to see are:

        • "TV_pet_name"

        Both pages are using the same template, but they don't show the same TV input options (if that makes sense). If my only option is to create two different templates and assign access to each then so be it.

        Hope that helps... thank you again for your time!



          • 4172
          • 5,888 Posts
          Its good practice to have as less conditional filters or if-snippet-tags as possible.
          In your case, it may be better to have different templates put together with chunks, for example like that:

          <html>
          [[$head]]
          <body>
          [[$header]]
          [[$left]]
          [[$center? &TVchunk=`animal_TVs`]]
          [[$right]]
          </body>
          </html>


          and

          <html>
          [[$head]]
          <body>
          [[$header]]
          [[$left]]
          [[$center? &TVchunk=`pet_TVs`]]
          [[$right]]
          </body>
          </html>


          the center-chunk:

          <div class="content">
          [[*content]]
          </div>
          <div class="TVs">
          [[$[[+TVchunk]]]]
          </div>


          the animal_TVs - chunk would have the TVs for animals and the pet_TVs - chunk the TVs for pets
          This way you don't need any conditional - filters and have every piece of code only once in reusabel chunks.

            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 37946
            • 70 Posts
            That's pretty close to what my html looks like on my actual template. I haden't thought about creating the center chunk like that though - I am going to give that a try.

            I am more interested in the manager itself. I should have attached a screenshot earlier - my apologies.

            In my specific case, I have a page called "map" which I allow admins to upload a map image (02.jpg). The map TV has access to my "BaseTemplate". Its the same template I use for all of my...inside/secondary pages. The only thing that is different between the map page and any other page is the map TV. That's why if I can help it - I don't really want to make another template just for one TV.

            So, on all pages within the manager show the map TV. But, on all but one case the map TV isn't applicable to the page. So if I could, I would like to find some way to hide the map TV image selector on all other pages except the map page.

            Thank you for your help so far. I greatly appreciate it!

              • 4172
              • 5,888 Posts
              Looking at this code,

                      $onResourceTVFormRender = $this->modx->invokeEvent('OnResourceTVFormRender',array(
                          'categories' => &$finalCategories,
                          'template' => $templateId,
                          'resource' => $this->resource->get('id'),
                          'tvCounts' => &$this->tvCounts,
                          'hidden' => &$hidden,
                      ));
                      if (is_array($onResourceTVFormRender)) {
                          $onResourceTVFormRender = implode('',$onResourceTVFormRender);
                      }
                      $this->setPlaceholder('OnResourceTVFormRender',$onResourceTVFormRender);
              
                      $this->setPlaceholder('categories',$finalCategories);
              


              it should be possible to remove a TV-category-tab with a plugin, which listens to OnResourceTVFormRender.
              Not sure if the same would be possible with form-customisation.

                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 37946
                • 70 Posts
                Woah - how did you know where to look/find that snippet? I am completely unfamiliar working with plugins (obviously). smiley
                Thank you again for all of your time. Very much appreciated!
                  • 4172
                  • 5,888 Posts
                  was looking a lot thrue the code and still do, while building MIGX.
                  So, I think, I know some parts, where they are and how they work.

                  MODX is well organized and you'll find this piece of code here:
                  https://github.com/modxcms/revolution/blob/develop/manager/controllers/default/resource/resource.class.php#L363

                  regarding the plugin, will look later for it.
                    -------------------------------

                    you can buy me a beer, if you like MIGX

                    http://webcmsolutions.de/migx.html

                    Thanks!
                    • 37946
                    • 70 Posts
                    Neat!
                    No worries - this will give me a great place to start. Thanks again for all your time.