We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • Please use only placeholder tags in the SwitchTemplate setting to define variable chunks as template. It should not work with resource field tags …

    Since 'template' resouce field contains the template id, you have to call the chunk with x_m, where x is the id of the template. It does not work with the name. [ed. note: Jako last edited this post 9 years, 1 month ago.]
      • 49325
      • 10 Posts
      Quote from: Jako at Mar 11, 2015, 11:47 AM
      Please use only placeholder tags in the SwitchTemplate setting do define variable chunks as template. Maybe it will work with resource field tags too, but that could change …

      Since 'template' resouce field contains the template id, you have to call the chunk with x_m, where x is the id of the template. It does not work with the name.

      Okay Jako, I'll test using chunks instead of templates and using ids instead of names.
      Why not use the same "placeholder" method also for templates? Any specific substitution problem?

      Thanks
        • 49325
        • 10 Posts
        With chunks it works!

        Just a little issue.
        Is no chunk is found an error is logged and the generated page is blank.
        Is it possible to fallback to the original template?

        And again, as said above, why not use the same "placeholder" method also for templates? Any specific substitution problem?

        ROb
        • For the blank page, please try this: http://revo.partout.info/extras/_packages/switchtemplate-1.1.1-b1.transport.zip

          The variable chunk/template name inside a SwitchTemplate setting is set by MODX getChunk method. It does not allow resource field tags (as far as I know).

          Inside that chunk/template you could use resource field tags. [ed. note: Jako last edited this post 9 years, 1 month ago.]
          • Does the beta package work as wanted? Do you have any issues with it?
              • 49325
              • 10 Posts
              Sorry Jako but I hadn't time to test it yet.
              I'll check it soon and I'll give you my feedback.

              ROb
                • 48532
                • 23 Posts
                Hey Jako,
                first: great plugin! Comes in handy quite often. Maybe you have a quick idea or even solution for this.

                I am running into the problem that I can't register a CSS file (via snippet call) when using switchTemplate. The setup is that I have a code for listing some elements and a detailcode for a detail view for each element. Switching between the templates works great. For test purposes I register the CSS file in a chunk that is used on every page (page head). Injecting the CSS works without problem on the listing and every other site. But NOT on the detail page.

                Every other snippet runs smooth on the detail view, e.g. echoing the current user etc. Just everything with $modx->registerClient* doesn't seem to be executed. No matter if caching is on or off.
                • Have to debug that and look when MODX inserts the registered Styles/Scripts in the output.
                    • 48532
                    • 23 Posts
                    Jako, is there any workaround to make system events, in this case OnWebPagePrerender, firing? I am trying to alter/inject some things based on the content with a plugin which is hooked to the OnWebPagePrerender.

                    With OnLoadWebPageCache I haven't had any success either; it works for "normal" sites to e.g. simply attach a text, not for switchTemplate. Like with
                    $src = &$modx->event->params['resource']->_content;
                    $src = $src . 'testing things';
                    $modx->log(modX::LOG_LEVEL_ERROR, 'OnLoadWebPageCache successful');

                    The event is active and firing (always 2 times for switch template, once for "normal" as my log shows). Priority is 1 for my plugin, 2 for switchtemplate.

                    SwitchTemplate caching is true, inside as content-to-change I have some migxLoops (cached).


                    • I don't think that you could use the normal MODX events on this. SwitchTemplate has to bypass the resource caching that is triggered during normal parsing process. This is only possible by using an own parsing process for switched templates. Sadly you don't have any events in that process anymore (at the moment).