We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 40557
    • 5 Posts
    Hey,
    how do I get this guy running?
    function tv($name)
    {
    	$id = $modx->resource->get('id');
    	$tv = $modx->getObject('modTemplateVar', $name);
    	return $tv->renderOutput($id);
    }


    Where can I get the $modx object from?

    Thanks smiley
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      In a function, you have to add

      global $modx;
        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
        • 40557
        • 5 Posts
        I just want to get the TV's content.
        function tv($name)
        {
        	global $modx;
        	$id = $modx->resource->get('id');
        	$tv = $modx->getObject('modTemplateVar', $name);
        	return $tv->renderOutput($id);
        }


        It gives me the first tv of another page, no matter which name I give it /:
          • 40557
          • 5 Posts
          Yeah, this one works fine:
          function tv($name)
          {
          	global $modx;
          	return $modx->resource->getTVValue($name);
          }
            • 22303 MODX Staff
            • 10,725 Posts
            Quote from: zimt28 at Jul 20, 2012, 04:07 PM
            I just want to get the TV's content.
            function tv($name)
            {
            	global $modx;
            	$id = $modx->resource->get('id');
            	$tv = $modx->getObject('modTemplateVar', $name);
            	return $tv->renderOutput($id);
            }


            It gives me the first tv of another page, no matter which name I give it /:

            You have to specify the field to search by if not searching by primary key.
            $tv = $modx->getObject('modTemplateVar', array('name' => $name));