On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • This is a Support/Comments Thread for SwitchTemplate
    http://modx.com/extras/package/switchtemplate

    SwitchTemplate changes the template of a MODX resource on the fly with a request parameter. Different settings with different setting keys could be set in a custom manager page.

    With each setting a different template could be used to output the resource. As well the template type could be set to chunk or template. If the template type is chunk the resource variables and template variables are prepared as placeholder before the chunk is parsed. The caching of the output of SwitchTemplate could be enabled for each separate setting. The output is cached separate for each resource and each setting. Each setting could be enabled or disabled for selected resources.

    SwitchTemplate could be used for different purposes: As Ajax connector, as language switcher ...

    Bugtracker and hotfixes on:
    https://github.com/Jako/SwitchTemplate

    Change Log:
    SwitchTemplate 1.0.0 (September 27, 2014)
    * initial release
    • Hi Jako.
      This sounds promising.
      Can I use this to do template switching on mobile detector as well?
        Rico
        Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
        MODx is great, but knowing how to use it well makes it perfect!

        www.virtudraft.com

        Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

        Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

        Maintainter/contributor of Babel

        Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.
      • Should be possible. If the mobile detector is a PHP based plugin, this plugin has to be called before the SwitchTemplate plugin is executed (it runs on OnLoadWebPageCache/OnLoadWebDocument) and it has to set the $_REQUEST key that triggers switchtemplate (default key is 'mode') – it could also set a cookie, but that is regarded only with the next load of the page. If the mobile detector is javascript based, the detector should redirect to the page with a get parameter or with a cookie.

        SwitchTemplate parses the templates itself with modx->getParser()->processElementTags and exits before the normal execution of the MODX parser, so maybe there are some glitches – i have tested it with getResource template chunks and FormIt calls to get different output for normal pages and Ajax results.

        If you use SwitchTemplate to switch to another template, remember that it uses the TVs available in the original template. [ed. note: Jako last edited this post 6 years, 8 months ago.]
        • Can SwitchTemplate be used also with different templates for differente resources?
          From the doc, the property "Chunk/Template Name" seems unique.

          Thanks!

          ROb
          • This is not possible out of the box.

            There are several ways thinkable to enhance the Plugin/CMP:
            - Change that field into a grid (not that flexible)
            - Use placeholders in that field content filled with the current resource content (and maybe template variables content).

            What do you want to achieve?
            • I didn't understand the second way.

              Any way to insert a "SwitchTemplate" template field inside the resource page (maybe in Settings tab) of the manager in which I can specify an alternative template?

              All the settings of SwitchTemplate remains inside the actual SwitchTemplate settings page, but if a specific resource level setting is present then alternative template will be used instead of the general one.
              Did I explained it well?

              Thanks Jako!
              • Second way is the same as you want.

                The "Chunk/Template Name" field contains i.e. '[[*templatevar]]SwitchTpl' and the TV template var is filled for a resource with 'whatever'. Then the alternate template for that resource is changed to 'whateverSwitchTpl'. The other resources use the 'SwitchTpl' alternate template.
                • That would be very nice! I think this is the best solution...
                  What do you think about?

                  • Hello, i have a problem.
                    I have installed SwitchTemplane and Wayfinder.
                    If i call page with main template, wayfinder shows resources with subcategories, like:
                    Page1
                    --Page11
                    --Page12
                    Page2

                    If i call page with switched template, wayfinder shows only first level of resouces, like:
                    Page1
                    Page2

                    modx-2.3.2
                    switchtemplate-1.0.1
                    wayfinder-2.3.3
                    cache off

                    Could you pleas look why is this happening?
                    • What does the Wayfinder snippet in the switched template look like? Are the two snippet calls the same on both templates?
                        Studying MODX in the desert - http://sottwell.com
                        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                        Join the Slack Community - http://modx.org