We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22827
    • 129 Posts
    I am converting a site to MODx.

    The original site has some pages where the content is duplicated into pages where the only real difference is the theming.

    What I would like to do is not duplicate all these pages, but simply alter the theming depending on how they were arrived at.

    So lets say the contacts page is document ID 60 (which ends up as 60.html), themed in "blue". I’d like to do something like:

    http://site.com/60.html - this comes out normal, or:
    http://site.com/60.html?theme=green - this passes "green" into a TV called "theme", then I just pull in the right css etc based on the TV.

    Any ideas how I can achieve this?

    The other way I can think of doing this is to store the content in a chunk or another document, and then have seperately themed documents that pull in the content from chunks or other documents. The problem with this idea is that I don’t want the content editor having to understand how to edit a chunk...

      • 22827
      • 129 Posts
      By the way, here is the original and the theme changing achieved by duplicating the document:

      https://www.prbwines.com.au/stleonards_winery_our-people.aspx
      https://www.prbwines.com.au/allsaints_winery_our-people.aspx

      Thanks
        • 9130
        • 171 Posts
        If the changes between the themes are only the css file included it should pretty easy to write a snippet that does that.

        If you need the ability to switch the full template of the page take a look at the TemplateSwitcher plugin but this might be an overkill in your case.
          • 22827
          • 129 Posts
          Yeah I think the template switcher may be overkill. I am not sure how I could use a snippet through.. How would the snippet know the context in which a page was run?

          I just saw that a weblink will accept TVs. Is there any possibility that a weblink to a document would override the TV of the documnet with the TV in the weblink?! Probably not.

          How about this - lets say I have a document that pulls in a @DOCUMENT - if they both have the same TV set, which one wins?

            • 22303 MODX Staff
            • 10,725 Posts
            Quote from: paulkoan at Mar 04, 2009, 08:24 AM

            Yeah I think the template switcher may be overkill. I am not sure how I could use a snippet through.. How would the snippet know the context in which a page was run?
            A snippet can see any of the variables available during the request, so you could easily just do this in a snippet called EchoTheme to echo out the value you passed in the request:
            <?php
            $output = isset($_GET['theme']) && !empty($_GET['theme'] ? $_GET['theme'] : 'default';
            return $output;
            ?>

            That snippet would echo the theme name anywhere you put the snippet, i.e. [!EchoTheme!]

            [PLEASE NOTE that this code is bad, in that you would want to do more to validate the value of $_GET[’theme’] before echo’ing back into your page content; malicious people love when you do not validate user input like that...]

            Quote from: paulkoan at Mar 04, 2009, 08:24 AM

            I just saw that a weblink will accept TVs. Is there any possibility that a weblink to a document would override the TV of the documnet with the TV in the weblink?! Probably not.
            No, a weblink is a redirect to another page entirely.

            Quote from: paulkoan at Mar 04, 2009, 08:24 AM

            How about this - lets say I have a document that pulls in a @DOCUMENT - if they both have the same TV set, which one wins?
            @DOCUMENT only pulls in the content field from the specified document. Any tv values that are parsed in that pulled content would applied from the document that was actually requested.
              • 22827
              • 129 Posts
              Quote from: OpenGeek at Mar 04, 2009, 08:57 AM

              Quote from: paulkoan at Mar 04, 2009, 08:24 AM

              Yeah I think the template switcher may be overkill. I am not sure how I could use a snippet through.. How would the snippet know the context in which a page was run?
              A snippet can see any of the variables available during the request, so you could easily just do this in a snippet called EchoTheme to echo out the value you passed in the request:
              <?php
              $output = isset($_GET['theme']) && !empty($_GET['theme'] ? $_GET['theme'] : 'default';
              return $output;
              ?>

              That snippet would echo the theme name anywhere you put the snippet, i.e. [!EchoTheme!]

              [PLEASE NOTE that this code is bad, in that you would want to do more to validate the value of $_GET[’theme’] before echo’ing back into your page content; malicious people love when you do not validate user input like that...]

              Yeah for sure!

              Ok, the snippet seems the best way to go. The shame about this is that when the page is shown in "blue" mode, there are different images in the content as to when it is in "green" mode. In order to apply the snippet, I have to break the wysiwyg nature of the page in the editor and have the snippet choose the right image depending on the GET variable.

              My newness to MODx is making me wonder if there isn’t a clever way to swap the images and css based on a GET variable, without putting snippet calls in the middle of the content?
                • 22303 MODX Staff
                • 10,725 Posts
                Set a placeholder in the snippet and use [+placeholder+] tags with the page uncached, or use a plugin attached to the OnWebPagePrerender to replace content however you want.
                  • 22827
                  • 129 Posts
                  Yeah, I was thinking of a pagerender plugin.

                  Having the placeholders in the content would break wysiwyg in the same way as a snippet call wouldn’t it? Or am I missing something?