We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8109
    • 128 Posts
    Hi, I’m new to snippit creation, and my php skills are weaker than the documentation of the modX API.

    I’ve learned how to get the id of the current document’s template using

    $modx -> documentObject[’template’]

    but what I want is the current document’s template’s name. There is a templateObject, but there’s no documentation for it. I read that for revolution the name is called ’templatename’, though I’m not sure if this is true for 0.9.6, but whatever the case I’m stuck on how to return the template name to a variable.

    Thank you so much for tolerating my current level of incompetence.

    By the way, this is for a snippit I’m dveloping that will insert a chunk in a template if the current template is the named template, thusly:

    [[ifSnippit? &template=`templatename` &trueChunk=`chunkName`]]


      Revo 2.0.8-pl
      • 10487 MODX Staff
      • 1,535 Posts
      Hi, you’ll need to initiate a query to get the template name - this’ll work:
      $templateName = $modx->db->getValue('SELECT templatename FROM '.$modx->getFullTableName('site_templates').' WHERE id='.$modx->documentObject['template']);

      Hope that helps smiley
        Garry Nutting
        Senior Developer
        MODX, LLC

        Email: [email protected]
        Twitter: @garryn
        Web: modx.com
        • 8109
        • 128 Posts
        Wow, geez, didn’t think it’s be so hard to access! Well, it’s not that hard, but I’d never have figured it out... thanks so much garryn!
          Revo 2.0.8-pl
          • 1526
          • 72 Posts
          hallo,
          I was looking for this (I want to set it as a class to the body, to have different CSS automatically linked to the template), but how do I use it? if I make a snippet [[GetTemplateName]] with the code:
          <?php
          $templateName = $modx->db->getValue('SELECT templatename FROM '.$modx->getFullTableName('site_templates').' WHERE id='.$modx->documentObject['template']);
          ?>

          I don't get any result.
          Where am I wrong?
          THank you
            MODx evo 1.5~1.6 ✪ Apache v 2.2.22 ✪ PHP v 5.3.10 ✪ MySQL v 5.1.61
            <°'iiii);
            • 4041
            • 788 Posts
            maybe this:
            <?php
            $templateName = $modx->db->getValue( $modx->db->select( 'templatename', $modx->getFullTableName('site_templates'), 'id='.$modx->documentObject['template'] ));
            
            return $templateName;
            ?>

              xforum
              http://frsbuilders.net (under construction) forum for evolution
              • 1526
              • 72 Posts
              :D yes, that's it.
              Thank you so much!
                MODx evo 1.5~1.6 ✪ Apache v 2.2.22 ✪ PHP v 5.3.10 ✪ MySQL v 5.1.61
                <°'iiii);