We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25383
    • 6 Posts
    Hi,

    I’d like to get the value of a specific TV i’ve created in a parent document (i’m using Modx 1.0.4)

    i’ve got a snipped called ZoomImage

    <?php
    $parent = $modx->getParent($iddoc,1,$field);
    return $parent[$field];
    ?>


    this works for the usual Modx objects ( http://rtfm.modx.com/display/MODx096/Document+Object )

    [!ZoomImage? &iddoc=`[*id*]` &field=`introtext`!]


    but to get the value of a personal TV (let’s name it "SpecialPic")

    [!ZoomImage? &iddoc=`[*id*]` &field=`SpecialPic`!] or
    [!ZoomImage? &iddoc=`[*id*]` &field=`[*SpecialPic*]`!] or
    Anything else...


    I’ve got a sql error (SpecialPic is not in the database !!!)

    Any Idea ? (it’s been 3 days of searching)

    Thanks,

    Max

    EDIT : the TV (SpecialPic) is authorized in all the templates i’m using

      • 20413
      • 2,877 Posts
        @hawproductions | http://mrhaw.com/

        Infograph: MODX Advanced Install in 7 steps:
        http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

        Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
        http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        That function only works for the resource variables; it uses the site_content table. That’s why it complains about not finding it in the database.

        You’ll need to use the getTemplateVarOutput() API function; here’s the example from the wiki

        $tvPr = $modx->getTemplateVarOutput(array("price"),$docid='2',$published=1);
        echo $tvPr['price'];


        Just replace the $docid=’2’ with the $parent variable. You’d probably be just as well off using the $modx->documentObject[’parent’] yourself since that’s what the getParent function uses, and all you want from it is the parent ID.

        $parent = $modx->documentObject['parent'];
        $tv = $modx->getTemplateVarOutput(array("$field"),$parent);
        return $tv[$field];
        


          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 25383
          • 6 Posts
          Quote from: mrhaw at Jan 13, 2011, 11:40 AM

          Check out getField http://modxcms.com/extras/package/?package=173

          Just perfect. thanks a lot !!!

          Quote from: sottwell at Jan 13, 2011, 11:46 AM

          That function only works for the resource variables; it uses the site_content table. That’s why it complains about not finding it in the database.

          You’ll need to use the getTemplateVarOutput() API function; here’s the example from the wiki

          $tvPr = $modx->getTemplateVarOutput(array("price"),$docid='2',$published=1);
          echo $tvPr['price'];


          Just replace the $docid=’2’ with the $parent variable. You’d probably be just as well off using the $modx->documentObject[’parent’] yourself since that’s what the getParent function uses, and all you want from it is the parent ID.

          $parent = $modx->documentObject['parent'];
          $tv = $modx->getTemplateVarOutput(array("$field"),$parent);
          return $tv[$field];
          




          I’ll try this tomorrow to get my own snippet, but GetField works perfectly for what i’ve asked.

          Thanks anyway, both of you.

          EDIT : Topic locked

          This discussion is closed to further replies. Keep calm and carry on.