We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8109
    • 128 Posts
    Hi folks, I’ve been kicking around this idea, and I’d love your feedback.

    For most pages on my site, the same basic overall template is used. What varies form template to template is the main content area, or sometimes a sidebar, where we might have certain TVs in use, tables of data, or what have you. Seems to me that maintaining a separate template file for each instance is a bit of a pain.

    My proposal is to have a snippit which returns a chunk based on the current document’s template. So you might have:

    [[ifTemplate? &template=`affiliate` &chunk=`affiliate_template`]]

    [[ifTemplate? &template=`article` &chunk=`article_template`]]

    and so on.

    Is there a flaw to this methodology? Caveats? I am planning on basing the ifTemplate code on another snippit I have called chunkIf, which I am using to insert a chunk based on whether a TV is set in the current document.

    A question: how do you read the current document’s template, by name?



      Revo 2.0.8-pl
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Why not just put the chunk in the template? Or make better use of TVs? How about a TV that offers a list of chunks with radio buttons or check boxes? @INHERIT is also useful. I rarely find it necessary to use more than one template.

        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
        • 20413
        • 2,877 Posts
        I once wanted a chunk being limited to a certain manager out of same reason.
        http://modxcms.com/forums/index.php?topic=34658.0

        What I ended up doing was using a include-file snippet or plugin as described here:
        http://modxcms.com/forums/index.php/topic,32493.0.html
        http://modxcms.com/forums/index.php/topic,30755.msg186652.html#msg186652

        Then with these options:
        http://modxcms.com/forums/index.php/topic,36267.msg219716.html#msg219716
        http://wiki.modxcms.com/index.php/Customizing_the_Manager_Homepage

        Now a logged manager-user that have access to the folder of "chunk"-file can edit it
        by clicking a link on manager home.
          @hawproductions | http://mrhaw.com/

          Infograph: MODX Advanced Install in 7 steps:
          http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

          Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
          http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
          • 7231
          • 4,205 Posts
          My proposal is to have a snippit which returns a chunk based on the current document’s template.
          Humm...to base it on documents template implies having different templates and thus you no longer are working with a single template.

          I often use document/parent/ultimateparent IDs as triggers for loading specific chunks or snippet and keep everything in a single template. But even so there are benefits to having templates, namely isolating TV groups...but I think that ManagerManager can do that as well.

          My favorite method is to use an include file and store the template in the file system then I can have 10 templates all based on the same file...updating one file will update all templates. However, I mostly use this on my own sites (or sites I manage) since most clients prefer to have a reference in the manager to the template code.
            [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

            Something is happening here, but you don't know what it is.
            Do you, Mr. Jones? - [bob dylan]
            • 8109
            • 128 Posts
            Let me expand then: Yes, having different templates for grouping TVs is part of the problem, in that you then have to maintain all these separate template files/code. But I thought that each template’s html code (too bad we have two used for the work templete in ModX) would then just be the same call to a chunk "globalTemplate", and that chunk would dynamically include other chunks based on the current document’s template. Sottwell said "why not jsut put the chink in the template", but that’s what I’m saying, I want only the chink pertaining to the current template to be inserted, while not having to maintain multiple templates.

            For instance you have a template that looks like this:

            {{siteTemplate}}

            and this chunk contains the following:

            {{siteHeader}}
            {{contentChunk}}
            {{siteFooter}}

            and then the "contentChunk" is as in my original post above, with dynamically called chunks depending on the current site’s template. Thus, every template is the same chunk call.

            Sottwell’s idea to have a TV with a list of chunks and such seems to duplicate teh very idea of a template, and anyway, for large and complex sites, thsre are many reasons why one might want more than one template. THis is the situation I’m describing. Once I get a working snippit I’ll post it for further comment.

            Cheers!



              Revo 2.0.8-pl
              • 30497
              • 245 Posts
              Oh, you just brought up one of my favorite MODx subjects!

              I make heavy use of PHx to do exactly what you are saying - create more complex templates that can deliver a wider variety of page views. Specifically, I use IF statements in PHx, primarily based on the way I structure the document tree (parent-child relationships), to achieve this. It is great! Maybe I need to do a blog post about this. It is a kick of mine, to see how far I can get with a single template, but still have a sensible and clean template layout that is manageable.
                • 5340
                • 1,624 Posts
                Quote from: towerofbabel at Jun 28, 2009, 03:08 PM

                Oh, you just brought up one of my favorite MODx subjects!

                I make heavy use of PHx to do exactly what you are saying - create more complex templates that can deliver a wider variety of page views. Specifically, I use IF statements in PHx, primarily based on the way I structure the document tree (parent-child relationships), to achieve this. It is great! Maybe I need to do a blog post about this. It is a kick of mine, to see how far I can get with a single template, but still have a sensible and clean template layout that is manageable.


                Could you post an simple example here? smiley
                  • 30497
                  • 245 Posts
                  Quote from: Cipa at Jun 28, 2009, 03:36 PM

                  Quote from: towerofbabel at Jun 28, 2009, 03:08 PM

                  Oh, you just brought up one of my favorite MODx subjects!

                  I make heavy use of PHx to do exactly what you are saying - create more complex templates that can deliver a wider variety of page views. Specifically, I use IF statements in PHx, primarily based on the way I structure the document tree (parent-child relationships), to achieve this. It is great! Maybe I need to do a blog post about this. It is a kick of mine, to see how far I can get with a single template, but still have a sensible and clean template layout that is manageable.


                  Could you post an simple example here? smiley

                  Sure. Here is a complete template from one of my sites, which is a pretty simple template with straight forward use of PHx. I am returning different main content areas and a different footer (actually, either no footer or a footer) depending on ID of the document using the template:

                  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                  
                  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="he" lang="he" dir="rtl">
                  <head>
                  	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                  	<title>[*pagetitle*] | [(site_name)]</title>
                          <meta http-equiv="Content-Language" content="he" />
                          <meta name="keywords" content="[*metaKeywords*]" />
                          <meta name="description" content="[*metaDescription*]" />
                          <meta name="author" content="[(site_name)]" />
                          <meta name="copyright" content="" />
                  	<link rel="stylesheet" href="[~20~]" type="text/css" media="screen" />
                          <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
                          <link rel="alternate" type="application/rss+xml" title="RSS Feed" href="[~4~]" />
                          <base href="[(site_url)]" />
                  </head>
                  <body>
                  <div id="container">
                          <div id="header">
                          {{header}}
                          </div>
                  
                          <div id="mainMenu">
                          {{mainMenu}}
                          </div>
                  [+phx:if=`[*id*]`:is=`1`:then=`<div id="home"></div>`:else=`
                  <div id="main">
                  <div id="content">
                  <h1>[*longtitle*]</h1>
                  [+phx:if=`[*id*]`:is=`9`:then=`[*address*]`:else=``+]
                  [*content*]
                  <div class="clear"></div>
                  </div>
                  </div>`+]
                  [+phx:if=`[*id*]`:is=`1`:then=`<div class="clear"></div>`:else=`
                           <div id="footer">
                           {{footer}}
                           <div class="clear"></div>     
                           </div> <!--end footer-->`+]
                  </div> <!--end container-->
                  </body>
                  </html>
                  


                    • 5340
                    • 1,624 Posts
                    The only problem I see with having one template for multiple layouts is that all the TVs will be assigned to all the documents.
                    So when the client edits a page, he sees all the TVs but only some will be displayed on the frontend. Might be confusing

                    If it’s only one or two TVs, I guess it’s ok.
                    But when you have to manage 10 TVs with phx, I would suggest using different templates.


                      • 20413
                      • 2,877 Posts
                      @Cipa Check out ManagerManager! smiley
                        @hawproductions | http://mrhaw.com/

                        Infograph: MODX Advanced Install in 7 steps:
                        http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

                        Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
                        http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower