We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22097
    • 37 Posts
    Hi all, I came across a nice feature I have not read about here. Browsing through the code I found Placeholders.

    This gave me an idea. In snippets I often use a piece of HTML code that should be easily manageble. So that should be a chunk. But what if I need a structure that encapsulates a piece of snippet output between two pieces of HTML code. That would mean that I need two chunks, a begin chunk and an end chunk.

    Placeholders allow me to use chunks like they are templates (like template engines such as Smarty etc). I create a chunk {{TitleTemplate}} like this:
    <h1>[+MyTitle+]</h1>
    

    This is a very simple chunk, but you probably get the idea. The [+MyTitle+] is a placeholder.

    In my snippet I then call it like this:

    ... normal code determining the contents of $valueOfTitle...
    
    $modx->setPlaceholder("MyTitle", $valueOfTitle);
    $output .= "{{TitleTemplate}}";
    
    return $output;
    


    As you can see this allows for much cleaner snippets, and the snippet output is much more manageble by editting the chunk. I’m planning to clean up snippets like the NewsListing with this technique. Yet another seperation of code and layout.
      • 32963
      • 1,732 Posts
      Very nice tip Olaf. Very nice indeed smiley

        xWisdom
        www.xwisdomhtml.com
        The fear of the Lord is the beginning of wisdom:
        MODx Co-Founder - Create and do more with less.
        • 4673
        • 577 Posts
        Seconds here!

        nice!
          Tangent-Warrior smiley
          • 18397
          • 3,250 Posts

          Very nice tip

          Ditto.


          I’m planning to clean up snippets like the NewsListing with this technique

          Sounds great!

          • Great stuff Olaf! I converted a web application from another PHP framework earlier this year using this technique, though I simply have my snippets set all the placeholders, and then have multiple levels of templating ability by putting placeholders and or chunks inside the content along with the snippet call.

            For example, In my content I might have something like this:
            [[SnippetSetsPlaceholderValues]]
            <div>
            [+examplePlaceholderDirectlyInDocumentContent+]
            </div>
            <form>
            {{exampleChunkContainingFormRelatedPlaceholders}}
            </form>
            


            I’m working on a large extranet project conversion using this technique now, and am also working with some alternative data table and form generation techniques (which I’ll share if they turn into anything useful), as the project is mostly just a set of forms and tables for managing various data tables.
              • 34017
              • 898 Posts
              Great tip Olaf!

              Jason,

              What is your snippet [[SnippetSetsPlaceholderValues]]. How do you set this differently than Olaf did?

              Thanks,
              Chuck
                Chuck the Trukk
                ProWebscape.com :: Nashville-WebDesign.com
                - - - - - - - -
                What are TV's? Here's some info below.
                http://modxcms.com/forums/index.php/topic,21081.msg159009.html#msg1590091
                http://modxcms.com/forums/index.php/topic,14957.msg97008.html#msg97008
              • Quote from: ProWebscape at Jun 27, 2006, 12:49 PM

                Jason,

                What is your snippet [[SnippetSetsPlaceholderValues]]. How do you set this differently than Olaf did?

                Not an actual snippet; I was just reinforcing Olaf’s example with one of my own, based on a project I had been working on last summer/fall.
                  • 34017
                  • 898 Posts
                  Jason,

                  I see now. Thanks for still answering my dumb (rookie) question.

                  Chuck
                    Chuck the Trukk
                    ProWebscape.com :: Nashville-WebDesign.com
                    - - - - - - - -
                    What are TV's? Here's some info below.
                    http://modxcms.com/forums/index.php/topic,21081.msg159009.html#msg1590091
                    http://modxcms.com/forums/index.php/topic,14957.msg97008.html#msg97008
                    • 34162
                    • 1 Posts
                    Really smart!
                    However, with this type of multi-level templating a rendering procedure might become smarter than its inventor and changing a template might get a re-engineering task laugh
                    • Quote from: ppaul at Jun 28, 2006, 02:59 PM

                      Really smart!
                      However, with this type of multi-level templating a rendering procedure might become smarter than its inventor and changing a template might get a re-engineering task laugh

                      True that, but if the snippet is authored in such a way as to only set placeholders for replacing dynamic values in external templates, leaving the markup to the external template (be it a chunk or TV or whatever), the only re-engineering tasks should be trivial, and using snippets to provide conditional output is trivial as well, should you want to have the template designer have a little more control over the rendering logic (a la Smarty or any other templating solution that allows logical rendering).

                      Only thing missing is being able to explicitly define relationships between snippets and their dependent chunks, TV’s, etc. And that functionality is already part of the 1.0 effort. This will make possible the creation of robust manager and/or quickedit features to deal with managing these related components in a more organized manner.