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

    I was wondering if there’s a better way to handle this basic problem.

    My site uses three templates, t1, t2 and t3. All three templates use the main ’style.css’ file. Templates t2 and t3 are a little different from the main template, and reference their own css files (’t1.css’ and ’t2.css’) to override certain parts of the main style.css.

    Right now I’m using a separate header chunk for each template to keep the css in order, with the appropriate css information for each template in its respective chunk.

    I just have the feeling I’m taking the caveman approach (unfortunately my default setting) to this and would really like to hear how this is handled by more experienced folks.

    Thanks!

    Cris

      • 20413
      • 2,877 Posts
      You could use a snippet like this:
      Name: css
      <?php
      $templateid = $modx->documentObject['template'];
      if ($templateid=="1") {
      print 't1.css';
      } elseif ($templateid=="2") {
      print 't2.css';
      } elseif ($templateid=="3") {
      print 't3.css';
      }
      // or load default
      else { 
      print 't1.css';
      }
      ?>
      


      Then in your ONE header chunk:
      <link href="assets/templates/css-folder/[[css]]" rel="stylesheet" type="text/css" />
        @hawproductions | http://mrhaw.com/

        Infograph: MODX Advanced Install in 7 steps:
        http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

        Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
        http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
        • 5994
        • 46 Posts
        Mr. Haw thanks!

        I’ve configured my site with this and it works great. The only problem I have now is that I need to configure this so that two css files are printed out, one after the other.

        In the case of template 2, for example, I have to be able to print ’css1’ and then ’css2’ right after it. I’ve tried to figure out how to do this on my own but I can’t. How do I do this in php?

        Whether you respond to this request, you already got me 99% of the way to where I need to be with this and I really appreciate the help!

        Cris
          • 20413
          • 2,877 Posts
          <?php
          $templateid = $modx->documentObject['template'];
          $option1 = <<<END 
          <link href="assets/templates/css-folder/t1.css" rel="stylesheet" type="text/css" />
          <link href="assets/templates/css-folder/t2.css" rel="stylesheet" type="text/css" />
          END;
          $option2 = <<<END 
          <link href="assets/templates/css-folder/t1.css" rel="stylesheet" type="text/css" />
          <link href="assets/templates/css-folder/t3.css" rel="stylesheet" type="text/css" />
          END;
          if ($templateid=="2") {
          print $option1;
          } elseif ($templateid=="3") {
          print $option2;
          }
          // or load default
          else { 
          print '<link href="assets/templates/css-folder/t1.css" rel="stylesheet" type="text/css" />';
          }
          ?>


          Then instead of your header chunk, have the code inside the $options vars:
          $option = <<<END
           
          ...
          
          END;


          And just call the snippet in the templates.
            @hawproductions | http://mrhaw.com/

            Infograph: MODX Advanced Install in 7 steps:
            http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

            Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
            http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower