We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27023
    • 36 Posts
    In templates..

    Is it possible to have some sort of "IF" statement in my template for specific pages.

    Basically i want an if statement that says if the page = contact or an ID no. If the statement is true i want to reference a different css file.?

    Thanks
      • 33337
      • 3,975 Posts
      Zaigham (aka zi) Reply #2, 17 years ago
      Have a look at the PHx plugin.
        Zaigham R - MODX Professional | Skype | Email | Twitter

        Digging the interwebs for #MODX gems and bringing it to you. modx.link
        • 27023
        • 36 Posts
        Thanks

        Had a look at that but wasnt sure if i was going down the correct route.

        Will look into it in more detail now thanks grin
          • 3749
          • 24,544 Posts
          If it’s just a few pages that will have the alternate CSS file, it will be faster to create a Template Variable to hold the path to the CSS file and give it a default value of the path to the standard CSS file and then change that TV on the page(s) where you want to have a different one:

          <link rel="stylesheet" type="text/css" href="[*TvName*]" />


          PHX is kind of slow when it comes to conditionals.

          If it’s a bunch of pages, a snippet with a case statement for the various IDs that returned the path to the CSS file might be easier:

          Snippet Call:

          <link rel="stylesheet" type="text/css" href="[!GetCSSPath? &pageID=`[*id*]`!]" />

          GetCSSPath Snippet:

          <?php
          
          switch($pageID) {
              case '2':
              case '7':
                 return('path to CSS file');
                 break;
              case '9':
              case '12':
                 return('path to another CSS file');
                 break;
              default:
                 return ('path to default CSS file');
          }
          
          ?>
            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