We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 53269
    • 6 Posts
    I am trying to help a client of mine with her ModX site that was developed by a developer who went AWOL.

    I am learning as much as I can about ModX but it is taking some time.

    In the meantime, I am wondering if there is a way that I can load a different page template if a particular link in a list is clicked.

    For example, on http://www.edelmangallery.com/artists/artist-archive/artists.html clicking on any artist in the list will load the template 'tpl_artist_page'.

    I would like to load a custom template called 'tpl_artist_aage_gregoryscott' when the user clicks on 'Gregory Scott'. The url for the Gregory Scott page is: http://www.edelmangallery.com/artists/artists/o-z/gregory-scott.html

    It seems like a conditional statement in JS should work but I am not sure how to write the statement with ModX attributes or where to put the custom JS.

    Even better, is there a dynamic way within ModX to ask the Gregory Scott link to load a page template called 'tpl_artist_aage_gregoryscott'?

    Thank you for your thoughts!

    This question has been answered by abraswell01. See the first response.

      • 3749
      • 24,544 Posts
      Hi, and welcome to MODX. smiley

      First, a few small things that make communication easier:

      1) It's MODX now (not ModX) when referring to MODX in general.

      2) In PHP code the class is modX and the variable is $modx.

      3) We generally use the word "template" to refer to just the things on the Templates tab in the Elements tree of the Manager. I think the things you're talking about are usually called Tpl chunks. They are definitely "templates", but calling them that creates confusion with the modTemplate object.

      Now, to your questions.

      It looks like your site is already doing close to what you want. It's difficult to advise you without knowing how the site works now.

      My guess is that there is really just one page that all the links on the artists page point to: http://www.edelmangallery.com/artists/artists/

      A custom snippet on that page gets the name of the artist from the URL. It pulls in the generic tpl_artist_page Tpl and fills in the placeholders like the artists name and the images.

      The snippet also injects the JavaScript that handles inserting the artist's information for the individual sections. The JavaScript is probably also in a Tpl chunk with placeholders for the artists name so that clicking on a topic gets that artists information (either from the DB, files, or other Tpl chunks) - possibly with an Ajax call to a processor.

      If I'm right about all that, you could add JavaScript to the existing JS chunk with the same artist name placeholder used for the other sections and write your own processor (or maybe use an existing one) to pull in whatever Tpl chunk you want by sending the artists name in the data section of the Ajax call.

      I hope this makes sense and that I'm not too far off base on how the site works.

        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
        • 53269
        • 6 Posts
        Quote from: BobRay at Mar 01, 2017, 03:49 PM
        Hi, and welcome to MODX. smiley

        Thank you Bob! I appreciate your response and communication tips. MODX seems to be a pretty great CMS! I am happy this site has given me a good reason to learn it.

        I poked around a little after writing my post. I realize there probably is a more direct way to accomplish what I am looking to do and is probably a pretty basic question.

        It looks like the Gregory Scott page is a Static Resource. There is a 'Uses Template' drop down menu in the Documents tab for this resource.

        Is there a way to add my Tpl Chunk 'tpl_artist_gregoryscott_page (80)' to this drop down menu so I can select it to load for the Gregory Scott page?

        I have attached a screen shot below.

        I apologize that I didn't know how to ask my specific question before!

        Thank you for your help!
        Amy

          • 3749
          • 24,544 Posts
          No need to apologize, we were all new here once. smiley

          Yes, it should be easy to add your template (assuming that it's a Template, not a Tpl chunk).

          Just go to the Elements tab in the Manager, right-click on the "Templates" folder in the tree and select "New Template." Once you've entered the HTML code and saved the new template, it should show up in that dropdown (you may have to clear the cache first, but I don't think so).

          An alternative that can save you time and help prevent errors is to duplicate an existing template to use as a starting point. Right-click on another template in the list under the "Templates" folder and select "Duplicate Template." You can give a name for the new Template and save it, then right-click on the new Template in the tree (you may have to refresh the tree first to see it) and select "Edit Template." Edit it to meet your needs and save it.



            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
            • 53269
            • 6 Posts
            Quote from: BobRay at Mar 02, 2017, 01:18 AM
            No need to apologize, we were all new here once. smiley

            Yes, it should be easy to add your template (assuming that it's a Template, not a Tpl chunk).

            Just go to the Elements tab in the Manager, right-click on the "Templates" folder in the tree and select "New Template." Once you've entered the HTML code and saved the new template, it should show up in that dropdown (you may have to clear the cache first, but I don't think so).

            An alternative that can save you time and help prevent errors is to duplicate an existing template to use as a starting point. Right-click on another template in the list under the "Templates" folder and select "Duplicate Template." You can give a name for the new Template and save it, then right-click on the new Template in the tree (you may have to refresh the tree first to see it) and select "Edit Template." Edit it to meet your needs and save it.




            Thank you so much Bob! This all makes total sense and seems to be what I was missing.

            I bought your book as soon as I picked up the project. I have enjoyed the first chapters and look forward to having the time to read through it in full.

            Best wishes,
            Amy
            • discuss.answer
              • 53269
              • 6 Posts
              Just wanted to pass along my final solution in case it helps anybody else...

              The site I am working on is pretty massive. I was able to find a template chunk that was controlling the behavior I wanted to change but I was unable to figure out what was calling the template chunk. With that, writing a new template for my page would not solve my problem.

              I basically knew where I needed to change the code and what I needed to change the code to within the template chunk but I would need a conditional statement to say 'if artistLastName = Scott then ..(new code... , else run ...(original code)'

              Then I found the documentation for Output Modifiers on the modx.com site. I realized that it was very easy to write conditional statements within MODX. I just needed to use MODX syntax instead of javascript syntax.

              So I added :

              [[+artistLastName:is=`Scott`:then=`

              [[+extendedOne:is=``:then=``:else=`<a class="videoTriggerArtworkInside" title="vIdi[[+title:lcase:spacereplace:replace=`'==_`]]"><img
              src="[[!phpthumbof? &input=`/manager/templates/edelman/artwork/[[+image]]` &options=`w=185`]]"
              alt="[[+title]]"/></a>`]]
              `:else=`

              to my old code of:

              <div id="fancybox">
              <a class="fancybox" data-title-id="tId[[+id]]" rel="group" href="/manager/templates/edelman/artwork/[[+image]]"-->

              <img
              src="[[!phpthumbof? &input=`/manager/templates/edelman/artwork/[[+image]]` &options=`w=185`]]"
              alt="[[+title]]"/>

              <!--<img-->
              <!--class="lazy2" data-original="[[++img]]?input=/manager/templates/edelman/artwork/[[+image]]&options=w=180"-->
              <!--alt="[[+title]]" />-->
              </a>
              </div>

              and closed out my conditional statement with:
              `]]

              This now shows all of thumbnail images in an artist's series through the fancybox viewer UNLESS the artist's last name is Scott. In that case, the thumbnails will each load an individual video file as this artist is a video artist.

              And, many thanks to Bob for his guidance and encouragement!
                • 3749
                • 24,544 Posts
                I'm glad you got it sorted.

                Conditional output modifiers are notoriously slow, especially nested like that.

                If the page-loads are noticeably slow, you could replace that with a custom snippet, something like this (if I'm understanding your code):

                [[!ShowArt? &lastName=`[[+artistLastName]]` &extendedOne=`[[+extendedOne]]`]]


                /* ShowArt Snippet */
                $lastName = $modx->getOption('lastName', $scriptProperties, '', true);
                $extendedOne = $modx->getOption('extendedOne', $scriptProperties, '', true);
                
                if ($lastName == 'Scott' && empty($extendedOne) ) {
                
                   return '<a class="videoTriggerArtworkInside" title="vIdi[[+title:lcase:spacereplace:replace=`'==_`]]"><img 
                src="[[!phpthumbof? &input=`/manager/templates/edelman/artwork/[[+image]]` &options=`w=185`]]"
                alt="[[+title]]"/></a>';
                
                } else {
                   /* return something else */
                }
                
                  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