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

    I’ve just completed my first serious MODx site.
    http://www.verdantconsulting.co.uk

    Through this project I altered my approach regarding Templates/Chunks and TVs and would appreciate some feedback as I plan my next development.

    When learning MODx using some of the workthroughs I gained the impression that everything ’passed the buck’ to something else and it seemed for a while that finding the code that actually did some real work was quite difficult (usually a chunk called from another chunk (repeat) called from a template).

    I quickly realised that this was abstraction (probably) with responsibility for action moved into "one thing well" chunks. And another vital insight (which is perhaps obvious) is to ensure no code appears in the Content of a page. So e.g. when creating Accordions or Tabs the Content comes from TVs - rather than try to have jQuery ’HTML stuff’ mixed up with the text the user will manipulate.

    So, I started the project with a ’Generic Approach’. A GenericPage template which contained Generic-Header/LeftSidebar/RightSidebar/Footer Chunks.
    Plan being to have a limited number of Templates each related to the page structure. So there may be 12-20 pages but only 4-5 Templates

    But I found that most pages were different enough to need their own template so instead of a list of templates like this
    GenericT(emplate), SingleLeftSidebarT, SingleRightSidebarT, AccordionContentT, DittoContentT etc.

    I instead have
    HomePageT, NewsPageT, AboutUsT, ContactT, etc

    And then I have specific Page Chunks embedded into what are actually fairly standard page Templates (as I ended up keeping the structure of header/sidebars/footers constant. E.g.

    {{GenericHeader}} {{GenericSidebar-Left}}
    {{HomePageContent}}
    {{GenericSidebar-Right}} {{GenericFooter}}

    {{GenericHeader}} {{GenericSidebar-Left}}
    {{CaseStudyContent}}
    {{GenericSidebar-Right}} {{GenericFooter}}

    So, every Page Template only has {{OnePageSpecificChunk}} that is unique.

    And a final consideration. If a Page requires a TV then it requires a specific Page to assign that TV to, with the ’Generic’ approach this may not be do-able (but I’m not sure about that).


    So, the question or thought for the day. Should each page have its own namedTemplate (with the exception of Container stuff such as Articles/Blogs). Or should each PageStructureType have a Template (GenericApproach). Mindful of the TV to Template issue.

    I think the Generic approach perhaps has the advantage that should I wish to change the entire look of the site I need only change a few Generic Templates rather than edit lots of PageTemplates most of which are identical apart from the {{OnePageSpecificChunk}}. But as I found there were enough variations between pages that it wasn’t practical.

    Cheers
    Parthian


      • 25663 MODX Staff
      • 12,272 Posts
      I always try to minimize the number of MODx templates whenever possible. It sounds like you may be using Chunks when TVs might be more appropriate. Interesting article on a how another developer approaches it with Revo:

      http://ichosemodx.wordpress.com/2010/02/21/one-template-multiple-page-layouts-exploring-the-power-of-template-variables/
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 22704
        • 42 Posts
        Okay, I’m back on this after spending time on a zen-cart site and lots of thinking about Dynamic Content areas.

        From one extreme (appearing to need a Template for nearly every major page) to an improved approach where I should have used a TV with this approach
        http://wiki.modxcms.com/index.php/Create_TV-Based_Chunks

        So, instead of

        {{GenericHeader}} {{GenericSidebar-Left}}
        {{HomePageContent}}
        {{GenericSidebar-Right}} {{GenericFooter}}

        {{GenericHeader}} {{GenericSidebar-Left}}
        {{CaseStudyContent}}
        {{GenericSidebar-Right}} {{GenericFooter}}
        etc

        I would have instead one Page Template like this (without the real need for Generic Chunks)
        {{GenericHeader}}
        [*UserSelectedPageTypeChunk-TV*]
        {{GenericFooter}}

        So, when a new Document is created the editor indicates which layout or content specific Chunk is required via TV Radio buttons.
        This would reduce the number of Page Templates possibly to one.

        And the iChoseMODx approach linked to by rthrash could also be used (same concept).


        But, I use TVs with TextArea as extra Content Editors. E.g. for Sidebar content or jQuery Accordion Content. If there is only one template (at the extreme) then that Template would have to have associated with it every TV required for the entire site. Most of these would be Not Applicable for most pages (probably).

        This suggests that maybe a Dynamic TV Assignment feature would be useful. If the Editor selects the UserSelectedPageTypeChunk-TV radio button for pages with the Accordion then several TextArea TVs would automatically appear to allow the Editor to change the content of the Accordions (or sidebar text or whatever). If the Accordion page isn’t applied via the Radio buttons then those specific TVs don’t appear. (Maybe with AJAX or a Page Refresh to control the appearing/disappearing context sensitive TVs).

        Does this sound remotely sensible?

        The nearest to this idea that I’ve found is this from 2006. Uses Snippets for "what I want for my side columns is content that changes automatically following the site section the visitor is browsing"
        http://modxcms.com/forums/index.php/topic,294.msg37718.html#msg37718

        I think he was trying to get much the same result as me.

        Perhaps as an alternative approach the requirement to have unique TVs for Content editing on a particular Page is an indicator that a New Template is required.


        I hope the above makes sense.
        Any thoughts anyone?