We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 54277
    • 8 Posts
    I want to use template names to replace template IDs in some filter codes. For example in following codes,

    [[*template:eq=`18`:or:is=`54`:then=`<img src="[[*mainImg:phpthumbof=`w=1920&h=1280&zc=t&aoe=1`:default=`assets/templates/[[++templateFolderName]]/img/campus-cb-sky-large.jpg`]]" alt="">`:else=``]]


    Template ID 18 is named as "News Article"; Template ID 96 is named as "Department News Article".

    Is anyone could help me?

    This question has been answered by BobRay. See the first response.

    • discuss.answer
      • 3749
      • 24,544 Posts
      The simplest way would be to use an unused text field of the resource to store the template name (like introtext/summary, longtitle, menutitle, description).

      Then just put a tag for that field in your rowTpl chunk:

      <p>Template Name: [[+description]]</p>

      If those are all in use, another way would be to use a TV to store the template name, but you'd have to fill it in for each resource unless you write a plugin to set it when the resource is saved.

      Yet another way would be to use a custom snippet to get the template name (untested).

      In your row Tpl:

      <p>Template: [[GetTemplateName? &templateId=`[[+template]]` ]] </p>

      /* GetTemplateName snippet */
      $templateId = $modx->getOption('templateId', $scriptProperties);
      $template = $modx->getObject('modTemplate', $templateId);
      if ($template) {
          $output =  $template->get('templatename');
      } else {
          $output = "error getting template name";
      return $output;

        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