We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    That's odd, I would expect that if the headChunk was also uncached, any version would work. This kind of thing is common in Evolution, but pretty rare in Revolution.

    That said, I rarely nest anything very deeply. I tend to do all processing in the snippet (using placeholders for all the tags) because it's usually faster and more reliable.



    ------------------------------------------------------------------------------------------
    PLEASE, PLEASE specify the version of MODX you are using.
    MODX info for everyone: http://bobsguides.com/modx.html [ed. note: BobRay last edited this post 14 years, 1 month ago.]
      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
      • 40385
      • 75 Posts
      Quote from: BobRay at Sep 08, 2012, 03:53 AM
      That said, I rarely nest anything very deeply. I tend to do all processing in the snippet (using placeholders for all the tags) because it's usually faster and more reliable.

      This approach sounds very interesting...Do you have an example for me? I'm always extracting the head-section into an own headChunk (including site_url, seo TVs etc).This headChunk is nested in all of my templates. How would you setup such things with your approach?

      Thanks!
        • 39932
        • 483 Posts
        I nest a lot of Chunks, but only place Snippets in the "deepest ones". However, that being said, I have a lot of Templates. This means that my Chunks are very,very simple (0 to few output modifiers). Like BobRay I do all of my processing in Snippets. (I also avoid TVs like the plague unless they hold more than one piece of information.)
          Website: Extended Dialog Development Blog: on Extended Dialog
          Add-ons: AJAX Revolution, RO.IDEs Editor & Framework (in works) Utilities: Plugin Compatibility List
          Tutorials: Create Cross-Context Resources, Cross-Context AJAX Login, Template-Based Actions, Remove Extensions from URLs

          Failure is just another word for saying you didn't want to try. "It can't be done" means "I don't know how".
          • 39932
          • 483 Posts
          @Paul:

          Your results with Snippets do not surprise me. As I explained before, it kinda makes perfect sense to me, given that Snippets are not treated as "objects" in the same way.
            Website: Extended Dialog Development Blog: on Extended Dialog
            Add-ons: AJAX Revolution, RO.IDEs Editor & Framework (in works) Utilities: Plugin Compatibility List
            Tutorials: Create Cross-Context Resources, Cross-Context AJAX Login, Template-Based Actions, Remove Extensions from URLs

            Failure is just another word for saying you didn't want to try. "It can't be done" means "I don't know how".
            • 3749
            • 24,544 Posts
            There are quite a few ways to do it. Here's one.

            Say the headChunk has a the following tags:

            [[$Chunk1]]
            [[++SystemSetting1]


            Change those to:

            [[+Chunk1]]
            [[+SystemSetting1]



            In the template you'd put a snippet tag:

            [[!HeadChunk]]


            <?php
            /* HeadChunk snippet */
            
            $chunkContent = $modx->getChunk('Chunk1');
            $settingValue = $modx->getOption('Setting1',null, 'defaultValue');
            
            $fields = array(
                'Chunk1' => $chunkContent,
                'Setting1' => $settingValue,
            );
            
            return $modx->getChunk('headChunk', $fields);
            


            Any logic (like your Template option) would also be moved into this snippet. Since it's not nested, any of the versions we discussed should work.

            BTW, I should have mentioned this earlier. If the headChunk or any of the included chunks need to display fields or TV values from the current document, just use content tags for them (no need for toArray():

            [[*pagetitle]]
            [[*longtitle]]
            [[*TV1]]



            ------------------------------------------------------------------------------------------
            PLEASE, PLEASE specify the version of MODX you are using.
            MODX info for everyone: http://bobsguides.com/modx.html
              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
              • 39932
              • 483 Posts
              Also, like BobRay demonstrated, a lot of people overlook that Chunks may have properties too. So, you can avoid a lot of processing by simply adding a couple of Properties. Properties do not have to be declared explicitly, and may be used inline. (I prefer to declare them explicitly using a PropertySet).

              In Chunks, Properties automatically become placeholders.
                Website: Extended Dialog Development Blog: on Extended Dialog
                Add-ons: AJAX Revolution, RO.IDEs Editor & Framework (in works) Utilities: Plugin Compatibility List
                Tutorials: Create Cross-Context Resources, Cross-Context AJAX Login, Template-Based Actions, Remove Extensions from URLs

                Failure is just another word for saying you didn't want to try. "It can't be done" means "I don't know how".
                • 40385
                • 75 Posts
                Thanks guys for all the useful information! To be honest, I've never worked/thought about using property sets...but now it starts making sense. So what you're saying is that you can avoid a lot processing when specifying such things as ++site_url, ++modx_charset and $chunkA in a property set and then passing it to the chunk as placeholders?

                Two questions on this:


                • How is this different in terms of processing from just putting these directly into the chunk?
                • How is this method different from using the method BobRay suggested? For me it looks like that the only difference to BobRay's suggestion is that the processing is done via snippet while the above method is using modx "core" processing...
                [ed. note: paul_kemp last edited this post 14 years, 1 month ago.]
                  • 39932
                  • 483 Posts
                  Well, System Settings themselves don't use much processing, but that can help, yes.

                  BobRay's method and mine are extremely similar, and ultimately have the same results. You can set a placeholder manually in a Snippet or automatically by passing it to a Chunk. The result is the same. When BobRay is talking about processing, he is talking about the "choice of display", itemization of results, anything that requires calculation.

                  I imagine (BobRay would have to confirm this) that the both of us (BobRay and I) use both methods above, frequently. I know I switch back and forth quite often. Really, its not best to stick to just one, but to know when to use which.

                  Calculated Presentation : BobRay's
                  Optional Presentation : Mine

                  Web Design is like designing any other software. Each functional section may have its own requirements. If you want to limit the amount of duplication of work, but still have adequate performance, you have to pick the method best for the job.

                  For instance, if you just need a bunch of ids, don't use getResources. Make a Snippet that gets the ids. If you need to track multiple users, a comma delimited list TV may be better than a whole ton of TVs. If you need access to a parent Resources TVs, don't copy them onto the page, simply get the Parent and get the TVs you need. It's often the little stuff that break your design, not the big errors. Those are easy to fix (most times).

                  That being said, make something that works first. If it doesn't work, it will never work well. [ed. note: fuzzicallogic last edited this post 14 years, 1 month ago.]
                    Website: Extended Dialog Development Blog: on Extended Dialog
                    Add-ons: AJAX Revolution, RO.IDEs Editor & Framework (in works) Utilities: Plugin Compatibility List
                    Tutorials: Create Cross-Context Resources, Cross-Context AJAX Login, Template-Based Actions, Remove Extensions from URLs

                    Failure is just another word for saying you didn't want to try. "It can't be done" means "I don't know how".
                    • 3749
                    • 24,544 Posts
                    I agree completely.

                    There is overhead in running a snippet in MODX. MODX has to parse the tag for the snippet name and properties, merge properties from the tag with properties in property sets and default properties, find the snippet code, and then execute it. Running one snippet requires half the overhead of running two.

                    There's almost always a trade-off between convenience and speed, though. The fastest thing you can do is put *everything* (including all the HTML) in the snippet, but that will cost you in maintenance time.

                    The second fastest method is to use getChunk() with no second argument and use str_replace() to replace the placeholders yourself. This is a good compromise (especially if there are not a lot of placeholders) because getChunk() is fairly fast with no second argument since it doesn't have to parse the incoming chunk at all or deal with any properties. You can still use properties in the snippet tag (or property sets or default properties) to set options for the snippet. I use this method often (as do many of the MODX standard extras).

                    I usually leave System Setting tags alone as they are fast and usually not affected by parsing order.

                    I very rarely use a snippet that gets a chunk that contains another snippet tag (in fact, I rarely use chunks that have anything but placeholder tags in them).

                    By far the slowest thing you can do is to use output modifiers (especially conditional or math output modifiers). They are very convenient, but MODX has to take the time to parse them and figure out what to do before doing any real processing. Since you already know what you want done you can just code it and it will be done much faster.

                    The compromise method, for people who are not comfortable with PHP, is using the 'if' snippet, which is a lot faster than any output modifier.

                    When you think about the fact that your site's bounce rate can be affected by millisecond differences in page-load times, it's often worth trying to speed up the processing.

                    It's not relevant to this discussion, but it's worth mentioning that one of the biggest factors in page-load speed is the number of http requests, so if you have a lot of different images in your Template, it's worth using CSS Sprites for them so they're all retrieved with a single http request: http://www.alistapart.com/articles/sprites/



                    ------------------------------------------------------------------------------------------
                    PLEASE, PLEASE specify the version of MODX you are using.
                    MODX info for everyone: http://bobsguides.com/modx.html
                      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
                      • 40385
                      • 75 Posts
                      Makes all sense to me. You made your point! I'll try to adept all these techniques in my next project. Thanks for all the useful information and helping to figure this out.

                      Thanks