We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 41837
    • 4 Posts
    Hi everyone!

    I'm brand new to Modx - I had a client of mine that I inherited have their platform on Modx. I decided to leave it as I liked how it was all put together and have begun learning more and more about the CMS.

    We recently had a request come across from someone marketing their website that I wasn't sure how to address. I've been doing some basic research on how to do this, but so far it hasn't worked right. What we have are several scripts that need to be included on certain pages.

    So for example, let's say they have a page for CARS and a page for TRUCKS. The code we need to input needs to be dynamic in that if the page or subpages are being viewed for TRUCKS, we need to run this script (it's a Google code that goes under the <body> tag). However if you are not on TRUCKS, and it's any other part of the site, run this other script.

    It seems like a pretty simply IF THEN statement, but I'm not getting how MODx deals with this.

    I saw on a blog post someone created something like this:

    [[!If?

    &subject=`[[*body-class]]`

    &operator=`EQ`

    &operand=`home`

    &then=`[[chunk here]]`

    &else=`[[other chunk here]]`

    ]]

    But using it didn't work.

    What I've done so far is I've created the scripts as chunks so I can pull them in and I have an idea of where I need to include them on the main.html but not understanding exactly how MODx works is making it just not click.

    Can any veterans give me some advice on how to create this?

    Thanks in advance!
      • 10208 ☆ A M B ☆
      • 1,780 Posts
      What is main.html? Your template? Is it a static resource for the template?

      The simple way would be to use one template for cars and trucks, and another for the rest of the site. That way none of the other pages even call the script (because you won't have it in the other template at all).

      Oh, and to use If, you'll need to install the If package from package management first :~}
        Frogabog- MODX Websites in Portland Oregon
        "Do yourself a favor and get a copy of "MODX - The Official Guide" by Bob Ray. Read it.
        Having server issues? These guys have MODX Hosting perfected - SkyToaster
        • 18373 ☆ A M B ☆
        • 3,141 Posts
        Mark Hamstra Reply #3, 14 years ago
        Can you post that snippet you wanted to post in between [ code ] tags? Until we launch the new version of the forums (real soon now!!), tags tend to get eaten by the parser. They're not lost and will reappear with the new version, but it helps to help you to see the entire tags you posted smiley
          Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

          Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
          • 41837
          • 4 Posts
          sure... it's just a basic marketing script from Google.

          
          [!If?
          
          &subject=''
          
          &operator='EQ'
          
          &operand='home'
          
          &then='{{ remarketing-script }}'
          
          &else='{{ remarketing-script2 }}'
          
          ]]
          
          
          


          Those remarketing scripts are the chunks I tried to create.

          Yes - the main.html handles the primary template file - which is the header, footer, content, etc. Currently, because they only had 1 marketing script for the whole site, the code was a static script. Now since we need two different ones showing up I'm not working on trying to make this dynamic.

          I'm curious about the template concept you are saying... so basically create like a "main-trucks.html" file that's a complete duplicate of the "main.html" except the script is different? Is there anything else I would need to do or would the file just be available when I go in to look at that resource?

          Thanks!
            • 3749
            • 24,544 Posts
            It sounds like you may be confused about how MODX works. There are usually no "files" other than CSS, JS, and image files. The content of documents, chunks, templates, etc. is stored in the DB. When a page is requested, MODX gets the template associated with that page from the DB, then inserts the content for that page (from the DB) into the template, processes any tags on the page, and sends it off to the browser.

            I think what Frogabog is suggesting is a second template that is used for both car and truck pages. It would be just like the main Template, but with the addition of your tag from the post above.

            That tag is a snippet tag (though not quite correct) and it's designed to run the If snippet. Part of the reason it didn't work for you is that you've mixed the tag syntax of MODX Evolution and MODX Revolution. Also, as Frogabog says, you'd need to install the If snippet (which AFAIK, is not available for MODX Evolution).

            To help you, we need to know what version of MODX you're using.


            ------------------------------------------------------------------------------------------
            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
              • 41837
              • 4 Posts
              Hi BobRay thanks for the reply.

              It is a custom build from another company and sports their logos so I can't quite see if it says revolution or evolution, but if I were to guess I would say its evolution. It says 0.9.6.3 which seems to me quite a few versions behind.

              In following up with your suggestion, I think that's what I picked up from the other response in creating a new template file with the only difference being the script - however I'm not totally sure I understand how this functions.

              From what I see here, if I create a new template file in the file structure it doesn't automatically show up in the list. And if I create a new template in the Resources that doesn't make a new file either. That leads me to believe that I need to create the file manually and then point it to that url using the template resources? I am thinking that I'd duplicate "main" and then change it to "main-trucks". Then make a "main-trucks.html" file and then change the code in the template file to read:

              [*main_trucks_template_url*]
              


              Am I interpreting that correctly?

              Thanks!
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                That is a really ancient version of pre-Evo!

                This will be helpful to you http://sottwell.com/how-templates-work.html
                  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
                  • 10208 ☆ A M B ☆
                  • 1,780 Posts
                  Um... not really. :~}

                  Forget about the template file. Your template is a resource, and does not produce or use a .html file at all. If you want it to use a file as it's source (highly desirable for editing), you'll want to use an importFile snippet to inject the contents of a static file into the template.

                  In Revolution, you could do this with a static resource, but not in Evolution (I don't think...)

                  So what you need to do is paste the code from your .html template file directly into a new template resource in MODx. From there on out, (after saving) you'll see this template available for new documents/pages.

                  Make one template for the main site, and one for the cars and trucks pages. \

                  One nice way to create a template for MODx is to separate out the header, footer, and content/main area all into individual chunks. Then, if you need to modify any of these portions of the template, or use different code in different pages (like your cars and trucks), just edit or make a new chunk with the appropriate code and, insert that chunk into a new template.

                  Instead of a template with your whole html page's markup, you'll end up with a template that looks something like this:

                  { {carsNtrucks_header} }
                  { {pageBody} }
                  { {carsNtrucks_footer} }
                  


                  where carsNtrucks_header and carsNtrucks_footer are two chunks, each with just the header and footer code markup, and the pageBody chunk contains all the stuff in the middle with a [*content*] tag inside it, wherever you want to place the content that users enter in the manager.

                  I had to look up revolution 0.9.6 tag syntax to write this. I may have messed something up. Susan will set me straight though, and her tutorials are really incredible too. Do check them out.




                  [ed. note: frogabog last edited this post 13 years, 11 months ago.]
                    Frogabog- MODX Websites in Portland Oregon
                    "Do yourself a favor and get a copy of "MODX - The Official Guide" by Bob Ray. Read it.
                    Having server issues? These guys have MODX Hosting perfected - SkyToaster
                    • 41837
                    • 4 Posts
                    Great thanks for the help - I just got it all to work it seems. Appreciate everything guys!