We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 35176
    • 193 Posts
    Can same be done in Revo's Form Customizer?
      jealousy<>love
      • 3749
      • 24,544 Posts
      There is duplication in your templates, but when it's time to edit things like the header and footer, you only have to edit once.

      You could also use a TV to specify the Tpl chunk, in which case you'd only have one template:

      [[$DeclarationsAndHead]]
      <table>
      <tr>[[$MyHeader]]</tr>
      <tr>[[$[[*chunkName]]]]</tr>
      <tr>[[$MyFooter]]</tr>
      </table>
      </body>
      </html>
      
      


      If the TV had a default value of @INHERIT, you'd only have to set it in a few places.
        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
        • 37329
        • 10 Posts
        That's smart use of the new Revo parser, there, Bob! thx for that

        What I generally do is this: i create MODx templates for all the different information types that will be used in the website. I create a snippet 'FileTemplate'

        <?php
        # Snippet to include files from filesystem
        # [[FileTemplate? &file=`assets/templates/mytemplate/file.html`]]
        
        if ( !isset($file) || $file== "" ) return "No file specified."; //check if there's a file given.
        
        //Start the buffer
        ob_start();
        
        //include
        include $file;
        
        //get contents from the buffer
        $ob_contents = ob_get_contents();
        
        //and kill/delete the buffer
        ob_end_clean();
        
        //return it to MODx
        return $ob_contents;
        ?>
        


        In each template i reference a 'unified template' like so:
        [[FileTemplate? &file=`assets/templates/dito3/unified_template.html`]]


        This unified template holds the common elements.
        Then I use PHX (evo, indeed)

        	
        [+phx:if=`[*template*]`:is=`5`:then=`<!-- DitoBlogPost-->{{detail_ditoblogpost_ch_stpl}}`+]
        [+phx:if=`[*template*]`:is=`4`:then=`<!-- CampagneItem-->
        	{{detail_campagneitem_ch_stpl}}
        `+]
        


        and call the right chunks for the specific template.

        This approach allows a cascade where there is one containing template file ( unified_template.html ) and where specific subtemplates are called as function of the template or a specific TV within a template ( / information types )

        I think the snippet should work in revo too, and there is an 'if' snippet for Revo : http://rtfm.modx.com/display/ADDON/If

        Though perhaps in Revo you could use the template tag (which returns the template ID number ) inside the chunk's name (kind of like Bob suggested )

        like so:
        
        [[$showDetailBlogpost-[[*template]]]]
        [[$showCampaignItem-[[*template]]]]
        
        


        And you would create these chunks for a particular template (ID)
        showDetailBlogpost-3
        showCampaignItem-5

        I don't know whether calls to a non-existent chunk throw errors in revo.




          • 39932
          • 483 Posts
          While the general use of Templates to provide a full skeletal structure for an HTML document, this is not an imperative in Revo. Templates provide surrounding structure for resource based on the content type of the resource. A template itself has no content type and therefore has no restrictions on which documents use them.

          This distinction is important as the recognition of this fact improves (and speeds) development dramatically. For Partial HTML, it might be a simple template with only a div element encapsulating the content. For a JS Template, it might include a multi-line license comment prior to the the content, etc. These are also valid ways to use Templates.

          Sub-Templating is actually quite reasonable and pretty simple to implement, but would require a Snippet that reads the content of the specified "parent" via xPDO and replaces the parent's [ [*content] ] with its own content (via str_replace()). The downside/upside would be it wouldn't have the same TVs as the "parent" unless the TVs were given access to both templates. (This could also be done with a plugin, but would be harder to configure so it doesn't break "non-child" templates.) I think I'll write a tutorial on it, since I've seen several requests for a feature like this. When it is done, I'll place the link here. [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
            Is there some reason you need the output buffer? Otherwise, a single line would do it:


            return (isset($file) && !empty($file))? file_get_contents($file) : 'No File Specified');



            ------------------------------------------------------------------------------------------
            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
              • 3749
              • 24,544 Posts
              My experience has been: fewer templates -> easier maintenance. YMMV.



              ------------------------------------------------------------------------------------------
              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
                For those who wanted the Snippet, it is simple and parses the parent template too. Unfortunately, it does climb the hierarchy effectively without losing some content. For best results, currently, "nest" the Template inside a Template that is not "nested". From the Child Template call the Snippet with the parent ID, like so:

                    [[!inheritTemplate? $id=`4`]]
                


                It then takes the content from the "child" and places it in the "parent" where the [ [*content] ] is. It must be named inheritTemplate as it uses a preg_replace to remove itself and stop infinite parsing.

                Here is the code:

                <?php
                // Requires an Template ID
                    if (empty($id))
                        return '';
                    else
                    {//Get the Template
                        $parent = $modx->getObject('modTemplate', $id);
                    // Must be a valid Template ID
                        if (empty($parent))
                            return '';
                        $parent = $parent->get('content');
                    // Adjust the Child Content by removing the call.
                        $child = $modx->getObject('modTemplate', $modx->resource->get('template'));
                        $child = $child->get('content');
                        $sansSnippet = preg_replace("/((?m)(!{0,1}\[\[!inheritTemplate\?{0,1}.{0,}\]\]))/", '', $child);
                    // Get the content
                        $adjusted = str_replace('[[*content]]', $sansSnippet, $parent);
                        
                    // Clear the already processed content
                        $output = $adjusted;
                        $modx->resource->_output = $output;
                    }
                    return $output;
                

                [ed. note: fuzzicallogic last edited this post 13 years, 7 months 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".
                  • 37329
                  • 10 Posts
                  Thx, Bob for your input... although i have somewhat a clue about output buffering .. i' don't know why the original developer put it in there
                  so i guess your single line of code should do the trick; thx!

                  Quote from: BobRay at Aug 20, 2012, 09:25 PM
                  Is there some reason you need the output buffer? Otherwise, a single line would do it:


                  return (isset($file) && !empty($file))? file_get_contents($file) : 'No File Specified');



                  ------------------------------------------------------------------------------------------
                  PLEASE, PLEASE specify the version of MODX you are using.
                  MODX info for everyone: http://bobsguides.com/modx.html
                    • 3749
                    • 24,544 Posts
                    The output buffering might make sense in a plugin.

                    On second thought, I would replace ! empty() with file_exists().
                      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
                      • 35176
                      • 193 Posts
                      not sure if this is doable, but would it be possible to create two separate Modx installs, and use the second install to generate sub-templates. Then, share various files and folders between the two installs to keep them integrated as needed.
                        jealousy<>love