phpmodxmodx-evolutionmodx-templatestemplate-variables

MODX Evolution. It is possible to get Template Variable ID in template?


I need to know which ID the Template Variable (TV) has, to put it into a form in the template.

Something like this:

<input type="text" value="[template_variable_id]" />

Does MODX Evo have some special tag for it, which can be used in templates?


Solution

  • That’s because $modx->resource is always the currently loaded document. If you’re calling a snippet, you need to pass in the current ID:

    [[!mySnippet? &resourceId=`[[*id]]`]]
    

    Snippet mySnippet

      $resource = $modx->getObject('modResource',$resourceId);
        $template = $resource->get('template');
        echo $template;