We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    Northie, in the old docs, resource fields like pagetitle and introtext were often referred to (incorrectly) as Template Variables. This should no longer be the case.

    The term "Template Variable" is reserved for extra fields you create yourself ad Template Variable objects. Template Variables are (and always were) stored in a different table than the content fields (actually, several different tables).

    To get any of the standard resource fields, all you need is something like this:

    $rs = $modx->getObject('modResource', $id);
    $pt = $rs->get('pagetitle');
    $it = $rs->get('introtext);
    

    or, for the current document:

    $pt = $modx->resource->get('pagetitle');
    $it = $modx->resource->get('introtext');



    If you really want a TV and know it's name or ID, you can get it with:

    $rs->getTVValue('TvName');
    $rs->getTVValue(12);
    

    or, again, for the current resource:

    $modx->resource->getTVValue('TvName');
    $modx->resource->getTVValue(12);
    


    If you need the rendered output of the TV instead of its raw value:

    $tv = $modx->getObject('modTemplateVar', $tvId);
    $output = $tv->renderOutput($resourceId);
    

    or, for the current resource:

    $output = $tv->renderOutput($modx->resource->get('id'));
    



    If you want the TV for the current resource in a snippet, you can also send the TV as a property:

    [[!MySnippet? &tvVal=`[[*TvName]]`]]


    <?php
    /* MySnippet */
    $tvValue = $scriptProperties['tvVal'];



    ------------------------------------------------------------------------------------------
    PLEASE, PLEASE specify the version of MODX you are using.
    MODX info for everyone: http://bobsguides.com/modx.html
      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
      • 21792
      • 37 Posts
      OK, so my intentions have obviously not been understood or I'm doing things really wrong

      The code posted above is only the top part of the whole snippet.

      In this case I have been suing wayfinder, but I am not satisified with only getting a handful of "properties" - I wanted the pagetitle, the introtext and the values of about 4 template variables in each navigation element.

      All this was done before I found out about the "getResources" plugin...which is awkward to use to create navigation when you're used to wayfinder, also I don't think that the [[+my_TV]] was supported at the time....thank modx for updates smiley

      Okay, so now I've revisited this thread today for a different reason, thinking I could use the code I've written or something from one iof the replies...I want to get my pages as JSON, all the properties that could be publicly available