We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19872
    • 1,078 Posts
    I know that TVs can be assigned to templates, but what if I only have one or two templates? Is there a way to assign a TV to a specific resource or group of resources?

    This question has been answered by BobRay. See the first response.

      • 4172
      • 5,888 Posts
      usually, you have different templates for different TV-sets, but you can hide them with form-customization.
      But its easier, just to create different templates and put your template-code into a chunk.
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 19872
        • 1,078 Posts
        Thanks for responding Bruno:

        Not sure I follow your suggestion. I thought I was making progress by having fewer templates and making use of TV selectors. Perhaps I have not honed in on the optimum amount of templates?

        How do you hide them with form customization?

        I read something in the docs about making TVs accessible to certain resource groups, but I don't quite understand.

        Let's take one of my sites as an example. It has 8 pages/resources. Doesn't make sense to have 8 templates, when I can create one for the home page and then another for handling content on all of the other pages.

        Am I trying to be to controlling? My goal is to make the manager be as simple to view as possible — only the items needed for that page.

        I have however put many of my TVs into groups — especially those with a ton of options. Having them in groups helps with cleaning up the manager a bit, making it less overwhelming — but it does not prevent the site admin from just randomly checking a box and maybe putting a contact form on a page/resource that doesn't need a contact form.
          • 4172
          • 5,888 Posts
          what you are controlling with different TVs can mostly be done with different templates, while the template-code could be the same at each template.

          this is the code of a base-template:

          [[$templates_basis?
          &pagetitle=`[[*pagetitle]]`
          &headtitle=`[[*headtitle]]`
          &description=`[[*description]]`
          &keywords=`[[*keywords]]` 
          &pagetitle_1=``
          &pagetitle_2=`[[$pagetitle_h1]]`
          &content_chunk=`$basis_content`
          ]]
          


          this is another one with a contact-form

          [[$templates_basis?
          &pagetitle=`[[*pagetitle]]`
          &headtitle=`[[*headtitle]]`
          &description=`[[*description]]`
          &keywords=`[[*keywords]]` 
          &pagetitle_1=``
          &pagetitle_2=`[[$pagetitle_1]]`
          &content_chunk=`$kontakt_content`
          ]]
          


          And another one, which is a detail-page with items of custom-tables:

          [[!migxLoopCollection? 
          &packageName=`boersenlexikon` 
          &classname=`blQALink`
          &joins=`[{"alias":"QA","selectfields":"pagetitle,content"}]`
          &where=`{"theme_id":"[[!+lexikon_theme.id]]"}`
          &sortConfig=`[{"sortby":"pos"}]`
          &limit=`1`
          &tpl=`@CODE:[[+QA_pagetitle]]`
          &toPlaceholder=`h1_title`
          ]]
          
          [[$templates_basis?
          &pagetitle=`[[!+h1_title]]`
          &description=`[[!+lexikon_theme.description]]`
          &keywords=`[[!+lexikon_theme.keywords]]` 
          &pagetitle_1=`<h2><span class="pagetitle">A-Z</span>Böhms Börsenlexikon</h2>`
          &pagetitle_2=``
          &content_chunk=`!$LexikonThemeContent`
          ]]


          the template-code itself is in a chunk 'templates_basis' and is the same for all templates:

          <!DOCTYPE html>
          <html lang="de">
          [[$head]]
          
          <body class="full">
          
          <div class="container">
          [[+formit_successmessage]]
          <div id="header" class="row">
          <!-- some header code goes here -->
          </div>
          <nav>
          <div id="nav-level1">
          [[pdoMenu? 
          &startId=`0` 
          &level=`1` 
          &tpl=`nav_level1_rowTpl` 
          &outerClass=`nav nav-tabsx nav-level1`
          ]]
          </div>
          
          [[pdoMenu? 
          &startId=`[[pdoField? &field=`id` &id=`[[*id]]` 
          &topLevel=`1`]]` 
          &level=`1`
          &outerClass=`nav nav-tabsx nav-level2`
          ]]
          </nav>
          <div class="row" id="breadcrumb-container">
          [[pdoCrumbs? 
          &tplWrapper=`@INLINE 
          <div class="breadcrumbs col-xs-12">Sie sind hier: [[+output]][[$breadcrumb_anzeige]]</div>`
          &tplCurrent=`@INLINE <span>[[+pagetitle]]</span>`
          &outputSeparator=` > `
          ]]
          
          </div>
          
          <div id="content" class="row">
          <div class="col-sm-8 contentcontainer">
          [[$[[*header_chunk]]]]
          
          [[[[*show_slider:is=`1`:then=`$top_slider`:else=``]]]]
          [[[[*show_article_image:is=`1`:then=`$article_image`:else=``]]]]
          <div class="contentblock [[*hr-color]]">
          [[+pagetitle_1]]
          [[+pagetitle_2]]
          [[+article_open]]
          [[+content]]
          [[[[+content_chunk]]]]
          [[+article_close]]
          [[*crosslinks]]
          
          </div>
          </div>
          <div id="sidebar" class="col-sm-4">
          [[getImageList?
          &tvname=`sidebar`
          &inheritFrom=`parents,33`
          &tpl=`@CODE:[[$[[+sideblock]]]]`
          ]]
          </div>
          
          </div>
          
          <div class="row">
          <div class="col-xs-12" id="footer">
          <!-- some footer code goes here -->
          </div>
          </div>
          </div>
          <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
          <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
          <script src="js/magnificpopup.js"></script>
          [[$ouibounce]]
          [[$magnificpopup]]
          [[$floatify]]
          [[$googlecode]]
          </body>
          </html>
          

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

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 19872
            • 1,078 Posts
            I'm going to need more coffee:)

            Will review and see if I can wrap my brain around this.

            Thanks Bruno.
              • 4172
              • 5,888 Posts
              you just inject different placeholders to the template-chunk from the different templates.
              That's all.

              For some bigger code-parts like the content, it is a good idea not passing the rendered code itself into the placeholder, but for example
              &content_chunk = `$basis_content`

              and have in the template-chunk

              [[[[+content_chunk]]]]


              you could run into parsing-issues with

              &content_chunk = `[[$basis_content]]`

              [ed. note: Bruno17 last edited this post 8 years, 10 months ago.]
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 46039
                • 76 Posts
                This is a really frustrating issue for me too. Bruno17, the whole templating templates approach is great, but it just demonstrates the issue, in my opinion.

                Personally I feel that TVs having a template and resource relationship would make MODX a whole lot better.
                • I've read that TVs were never intended to be used as extra resource content fields, but as resource-specific template settings. Extra resource fields are supposed to be handed by custom resource types, extending the resource class.
                    Studying MODX in the desert - http://sottwell.com
                    Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                    Join the Slack Community - http://modx.org
                  • discuss.answer
                    • 3749
                    • 24,544 Posts
                    What you're thinking of is possible with both Form Customization and Element Category Access ACL entries. Form Customization is usually a better option, since it just hides the TVs on pages that don't need them. It has much fewer unpleasant side effects than using permissions.

                    That said, TVs are really designed to hold resource-specific data for all resources that share a template.

                    It's not clear to me whether you want to hide the TVs in the Manager or the front end (or both). Form Customization will hide them in the Manager, but not in the front end.

                    TVs, BTW, are fairly slow and inefficient no matter how you use them (though this is less important when the pages are cached).

                    In the front end, I tend to use chunks with a custom snippet rather than TVs for things I want to show only on certain pages. Here are some example snippets:

                    Put this where you want the specific content:
                    [[!ShowDisclaimer]]



                    /* ShowDisclaimer snippet */
                    $docId = $modx->resource->get('id');
                    
                    if ($docId == 12 || $docId == 14 || $docId == 23) {
                        return $modx->getChunk('MyChunk');
                    } else {
                        return '';
                    }
                    

                    /* ShowDisclaimer snippet (parent version) */
                    
                    $parent = $modx->resource->get('parent');
                    
                    if ($parent == 12 || $parent == 14 || $parent == 23) {
                        return $modx->getChunk('MyChunk');
                    } else {
                        return '';
                    }


                    /* ShowDisclaimer snippet (hide on certain pages version) */
                    
                    $docId = $modx->resource->get('id');
                    
                    if ($docId == 12 || $docId == 14 || $docId == 23) {
                        return '';    
                    } else {
                        return $modx->getChunk('MyChunk');
                    }
                    
                    
                      Did I help you? Buy me a beer
                      Get my Book: MODX:The Official Guide
                      MODX info for everyone: http://bobsguides.com/modx.html
                      My MODX Extras
                      Bob's Guides is now hosted at A2 MODX Hosting
                      • 19872
                      • 1,078 Posts
                      Bob:

                      This is exactly what I was wanting! Thank you.