We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • Quote from: ottogal at Dec 07, 2011, 01:52 AM
    I'm always wondering why people so eagerly avoid to have more than one template. Concerning performance, isn't it much better than using so many modifiers?
    I agree; many Templates with reusable or inherited sections via Chunks and/or Template Variables is a much better approach and can help avoid logic appearing in tags, which degrades performance.
      • 12410
      • 353 Posts
      Hi Guys,
      Trying to get the below snippet working. Any ideas how to tweak the syntax to make it work? For some reason
      [[!include? &file=`assets/templates/inc/newslisting.php]]
      is set for everything and the conditions are ignored.
      <?php
      $id='[[*id]]';
      
      if ($id = "3" || $id = "24" || $id = "35" || $id = "38" || $id = "42" || $id = "44" || $id = "47" || $id = "32"){
       echo "[[!include? &file=`assets/templates/inc/newslisting.php]]";  
      } 
      elseif ($id = "54" || $id = "64" || $id = "75"){
       echo "[[!include?&file=`assets/templates/inc/bloglisting.php]]";
      } 
      elseif ($id = "56"){
       echo "[[!include?&file=`assets/templates/inc/contact.php]]";
      } 
      else {
       echo "[[!include?&file=`assets/templates/inc/textContent.php]]";  
      };


      The logic I need is if a certain resource id then include some specific code otherwise use the default code

      THANKS


      This also wouldnt work for me:

      <?php
      $output = '';
      
      if ($id == "3" || $id == "24" || $id == "35" || $id == "38" || $id == "42" || $id == "44" || $id == "47" || $id == "32"){
       output = '[[!include? &file=`assets/templates/inc/newslisting.php]]';  
      } 
      elseif ($id == "54" || $id == "64" || $id == "75"){
       output = '[[!include?&file=`assets/templates/inc/bloglisting.php]]';
      } 
      elseif ($id == "56"){
       output = '[[!include?&file=`assets/templates/inc/contact.php]]';
      } 
      else{
       output = '[[!include?&file=`assets/templates/inc/textContent.php]]';  
      }
      return $output;
      


      and using
      [[!templateSwitcher? &id=`[[*id]]`]]


      Anybody...please [ed. note: howster last edited this post 12 years, 4 months ago.]
        • 22427
        • 793 Posts
        Perhaps it's just the missing of closing backticks?
        [[!include? &file=`assets/templates/inc/newslisting.php]]
        should be
        [[!include? &file=`assets/templates/inc/newslisting.php`]]
          • 4172
          • 5,888 Posts
          you can try this as a more flexible solution:

          <?php
          //[[!templateSwitcher? &newslisting=`3,24,35,38,42,44,47,32` &bloglisting=`54,64,75` &contact=`56` &default=`textContent`]]
          
          $id = $modx->resource->get('id');
          unset($scriptProperties['default']);
          
          foreach ($scriptProperties as $file => $ids) {
              $ids = explode(',', $ids);
              if (in_array($id, $ids)) {
                  $params['file'] = 'assets/templates/inc/' . $file . '.php';
                  return $modx->runSnippet('include', $params);
              }
          }
          
          $params['file'] = 'assets/templates/inc/' . $default . '.php';
          return $modx->runSnippet('include', $params);
          


          call it:

          [[!templateSwitcher? &newslisting=`3,24,35,38,42,44,47,32` &bloglisting=`54,64,75` &contact=`56` &default=`textContent`]]


          [ed. note: Bruno17 last edited this post 12 years, 4 months ago.]
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 42596
            • 45 Posts
            Bump!

            I know this thread is ancient but it's basically asking what I want to know...I was just wondering if anything has changed in 2 years?

            Ideally I would like to do something like

            [[!getContext:is=`web`:then=`doSomething`:elseif=`getContext`:is=`contextTwo`:then=`doSomethingElse`]]


            obviously this call doesnt make sense to modx but hopfeully you get the idea of what I am trying to accomplish...I have a modx install with 4 different contexts and sometimes only need small changes to each one. I dont want to use different templates as the differences are generally quite small and I dont want to have to change the same thing in 4 places every time i need to make a change...

            Many thanks!

            Matt [ed. note: cleanboy last edited this post 9 years, 6 months ago.]
              • 50923
              • 137 Posts
              Quote from: cleanboy at Oct 14, 2014, 01:07 PM
              Bump!

              I know this thread is ancient but it's basically asking what I want to know...I was just wondering if anything has changed in 2 years?

              Ideally I would like to do something like

              [[!getContext:is=`web`:then=`doSomething`:elseif=`getContext`:is=`contextTwo`:then=`doSomethingElse`]]


              obviously this call doesnt make sense to modx but hopfeully you get the idea of what I am trying to accomplish...I have a modx install with 4 different contexts and sometimes only need small changes to each one. I dont want to use different templates as the differences are generally quite small and I dont want to have to change the same thing in 4 places every time i need to make a change...

              Many thanks!

              Matt

              Have you made to find a solution?
                <a href="www.play2web.com" title="izrada web sajtova">Izrada web sajtova</a>
                • 4172
                • 5,888 Posts
                What exactly are you after, whats your usecase, exactly? There are several solutions posted in this thread.
                  -------------------------------

                  you can buy me a beer, if you like MIGX

                  http://webcmsolutions.de/migx.html

                  Thanks!
                  • 50923
                  • 137 Posts
                  Txanks mate i accomplished like this

                  [[getResourceField? &id=`[[BabelTranslation? &resourceId=`13`&contextKey=`[[*context_key]]`]]` &field=`DefaultPhoneNumber` &processTV=`1` &default=`Sorry, no data available`]]
                    <a href="www.play2web.com" title="izrada web sajtova">Izrada web sajtova</a>
                    • 50923
                    • 137 Posts
                    Quote from: Bruno17 at Oct 18, 2015, 01:50 PM
                    What exactly are you after, whats your usecase, exactly? There are several solutions posted in this thread.

                    Is it possible to access MIGx TV from another ID?
                      <a href="www.play2web.com" title="izrada web sajtova">Izrada web sajtova</a>
                      • 4172
                      • 5,888 Posts
                      for frontend or backend?
                        -------------------------------

                        you can buy me a beer, if you like MIGX

                        http://webcmsolutions.de/migx.html

                        Thanks!