We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10666
    • 68 Posts
    I have a question regarding template code management.
    For a website , I would need 5-10 top-level templates that would have a very different structure , let’s say some will have 3 columns , some will have 2/4 etc.
    I was thinking of the most efficient way to organize the template code to be able to maintain it easily and came up with a structure based on chunks , like this:

    <?xml version="1.0" encoding="iso-8859-1"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
    	{{head}}
    	{{body}}
    </html>


    head:
    <head>
    	{{content-type}}
    	{{metaDescription}}
    	{{metaKeyworkds}}
    	{{externalJS}}
    	{{externalCSS}}
    	{{title}}
    </head>


    content-type:
    <meta http-equiv="content-type" content="{{media-type}}; {{charset}}" />
    


    ...etc. I have around 20 chunks for a template.The best thing about this aproach, is that I could reuse some parts in other templates , parts like content-type ( text/html ), encoding , entire columns , footers etc , but I was wondering what would be the overhead of doing this , after all , I would have chunks 3-4 levels deep from the main chunk .How much speed do I sacrifice by doing this and what is the recommended aproach ?

    Thank you !
      • 36541
      • 222 Posts
      Quote from: Geo88 at Dec 27, 2006, 11:26 AM

      <?xml version="1.0" encoding="iso-8859-1"?>


      Be aware that using this declaration will throw IE6 in quirks mode. However, you should include it if you do want to use [tt]iso-8859-1[/tt] encoding instead of [tt]utf-8[/tt], which is default for XML documents (and XHTML is XML). According to W3C XHTML 1.0 recommendation the XML declaration is not required when default encoding is being used (see chapter 3.1.1. Strictly Conforming Documents).

      As to your main question, I think it’s a matter of preference. I use a simpler structure -- I put more code into templates if they do have a different structure. For example I use only one chunk for meta-data and fill the values with template variables. Anyway, there’s no standard as MODx is very flexible. You just have to find your way to do it. Good luck smiley
        This is the web: the only thing you know about who will come is that you don't know who will come.
        • 10666
        • 68 Posts
        WOW!
        Thanks a lot ! I just recently made some template changes (like the one you mentioned) and was wondering what broke my layout so bad in IE considering the amount of time spent reading on w3c standards and ie’s rendering issues .(I wasn’t far from the: "hitting-your-head-against-the-wall-for-having-to-code-for-IE-too" part >:().

        About the chunks in the templates. I would have no problem using chunks in templates scarcely. However, I assumed that because my chunks are deeply nested , to parse them all , modx would need to apply the same parsing(or whatever it’s called) algorithm recursively so many times, that it would slow down the site too much. Another assumption I made is that performance would degrade due to the fact that no subparts (chunks) are cached.
        So , to put it shortly , does the increase in flexibility degrades performance too much ? Am I designing the whole thing focused on too maintainability that it brings the site a big penalty on speed ?

        You also mentioned "one chunk for meta-data" that made me realize I could simplify some things in my current structure.

        Thanks once again grad for your help !
          • 36541
          • 222 Posts
          If I recall it correctly, the document parser takes ~20 cycles to parse nested chunks/placeholders/tvs etc. I guess that a heavy nesting may have impact on performance.

          Maybe someone from the dev team might provide some guidelines.
            This is the web: the only thing you know about who will come is that you don't know who will come.
            • 25663 MODX Staff
            • 12,272 Posts
            I almost always put my doctype and meta information into a single chunk, as well as my footer. I don’t see why breaking it down further would cause any serious performance issues, especially if caching is turned on.
              Ryan Thrash, MODX Co-Founder
              Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
              • 10666
              • 68 Posts
              Thank you all for your help !
              Case closed tongue .