We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14226
    • 8 Posts
    Hey guys,

    So currently I have my site set up like the following:
    Italian Foods (resource 1)
    - pizza (resource 3)
    - garlic bread (resource 4)
    Mexican Foods (resource 2)
    - burritos (resource 5)

    So basically I have category resources, then related articles as children to these parent resources.

    Up until this point, I’ve had a different template for each category, plus the base template which I use on the home page. [[*content]] is in the main area of the page.

    Looking at the how to make a blog in the Modx Rev documentation, I have edited the templates to show the title, date posted, etc. and also added a comments section with Quip.

    Now.. it seems to me that the category resources (say italian) would have a different template than it’s child. The child wants to show the comments, etc, but the category page just uses getResources to list all articles of that category. It looks weird when it formats that as a post and has a section for comments.

    Sorry this is getting a little longwinded.. but my point is.. The children articles inherit the parent’s template. Naturally, this means you’d have to set the template to the correct one every time you make a resource (which leaves a lot of room for human error).

    I would set the article template to be the default.. but I have a different template for each category. The page looks exactly the same, however it uses a different chunk for the navigation, because I want the (for ex.) Italian Foods link to be a different color when reading about Garlic Bread, to indicate that the user is in the Italian Foods section.

    I’m sure theres some way to simplify this.. could you guys help me out?

    Thanks a ton!
      • 3749
      • 24,544 Posts
      You should definitely be able to use the same template for all the food category container pages. If you use Wayfinder for the menu, you can use the &hereClass property to give the current doc and its ancestors a distinctive class.

      I think I would use the same template for all individual food pages and make it the default template, since you will be creating a lot more of those than anything else, and once the food category pages are all there, you’ll seldom create any more of them. It’s possible to create a plugin that would set the template of the food pages based on which category they are under, but I’m not sure it’s worth the trouble.
        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
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        You can easily use the same template but a totally different .css file for styling by using a Template Variable to specify the .css file name to use.
        <link rel="stylesheet" type="text/css" href="assets/templates/template-name/[[*stylesheet]].css" />


        This method can be used to show/hide columns and entire sections of a single template, allowing a single template for the entire site. Clever use of classnames for the <body> tag can determine the positioning and styling of all of the HTML elements. Take a look at the CSS Zen Garden demo to get the idea of what can be done with a single HTML structure and a .css file. In fact, there are several free HTML templates available that do just this; see the Multiflex template at http://www.1234.info/webtemplates/multiflex5/demo/index.html for an example.

        You can even use a radio-button type TV to make it easier to select which .css file to use on any given page.
          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
          • 14226
          • 8 Posts
          Thanks!

          I wasn’t aware of the hereClass. Here’s the code I used (in my template) for anyone interested:

          [[!Wayfinder?
          &startId=`0`
          &outerTpl=`menuOuter`
          &rowTpl=`menuRow`
          &innerTpl=`menuInner`
          &innerRowTpl=`menuInnerRow`
          &hereClass=`active`
          &firstClass=``
          &lastClass =``
          &excludeDocs=`7,19`
          &level=`1` ]]

          level = 1 is because all of my category resources are at the base level of 1, so articles arent grabbed

          hereclass = active is because i use the css class "active" to format for links if you’re on that page

          and i exclude docs 7 and 19 because those are my search and tags page, which i don’t want linked to from the main navigation bar.

          menuInner and menuOuter are chunks and have the same code:
          <ul>[[+wf.wrapper]]</ul>

          menuRow and menuInnerRow are chunks and have the same code:
          <li [[+wf.classes]]><a href="[[+wf.link]]" title="[[+wf.title]]" [[+wf.attributes]]>[[+wf.linktext]]</a>[[+wf.wrapper]]</li>

            • 28042 ☆ A M B ☆
            • 24,524 Posts
            Do NOT confuse templates (site templates, the HTML structure for the entire page) with the mini-templates used for displaying the output of Wayfinder or other similar snippets! That’s why we call them "tpls" and not templates, although by definition they technically are all "templates".

            The resource’s assigned template is applied to the entire page, and any snippet or other MODx tag output is inserted in the place where the tag is located. Tpls are (usually) applied repeatedly to each resource being processed by the snippet as the snippet loops through the list of resources it collected from its SQL query. They are also (again, usually) parsed internally by the snippet rather than by the main MODx parser, although the fact that the main MODx parser makes several passes over the resource makes it possible that MODx tags in each item output from within tpls will be parsed on a subsequent pass.

            Placeholders are used for the data for each item of the list. TV and resource variable tags ([[*...]] or [*...*] always refer to the value for the main resource being processed by the MODx parser, not for the individual resources being processed by the snippet. So if you have [[*pagetitle]] in a tpl, it will display the same pagetitle (that of the main resource) in each item the snippet produces.
              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
              • 3749
              • 24,544 Posts
              Quote from: sottwell at Apr 29, 2011, 12:25 AM

              Do NOT confuse templates (site templates, the HTML structure for the entire page) with the mini-templates used for displaying the output of Wayfinder or other similar snippets! That’s why we call them "tpls" and not templates, although by definition they technically are all "templates".

              Excellent point. Technically, they are now Tpl chunks. They are template-like, but it saves a whole lot of confusion if the word Template is reserved for the things in the modx_site_templates table (or in Revo -- template objects).
                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
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                they are now Tpl chunks
                Actually they usually don’t have to be chunks. They can be defined directly in the snippet’s parameter, they can be taken from external files, they can be defined as part of an external configuration file. The latter is my personal preference, as being defined as a variable in an external config.php file allows for extreme flexibility in conditional tpl structures. True, there’s phx, but I’ve run into a few cases where that wasn’t flexible enough, and having conditionals defined in the one config.php file was a lot cleaner than creating new phx extensions.
                  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
                  • 3749
                  • 24,544 Posts
                  Good point again. They’re only Tpl chunks when they’re chunks, but for most snippets and plugins that use them, the &tpl parameters take the name of a chunk.
                    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
                    • 14226
                    • 8 Posts
                    For tpl I’ve used chunks. Wasn’t aware I could define the html straight in the wayfinder call. (I’m using Revo btw)

                    Anyway, I did the wayfinder call in my template. Some of what you said went a little over my head but everything has been working well so far.

                    Thanks again for all your help