We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37126
    • 37 Posts
    Hi
    Should this work work in the default value of a TV

    @EVAL $resourceId = 1;$tvId = 40;$tv = $modx->getObject('site_tmplvars', $tvId);$val = $tv->getValue($resourceId);return $val
    


    Thanks

    Using MODX Revo 2.24
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      It should (except for the missing ; on your return directive). Did you try it?
        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
        • 37126
        • 37 Posts
        Hi,
        Yes I spotted that after posting but I still got an Error 500 and in the error log I got this

        [2012-10-09 06:58:30] (ERROR @ /stage/index.php) Could not load class: site_tmplvars from mysql.site_tmplvars.
        [2012-10-09 06:58:30] (ERROR @ /stage/index.php) site_tmplvars::load() is not a valid static method.

        Thanks
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Ok, here you go... http://rtfm.modx.com/display/revolution20/Accessing+Template+Variable+Values+via+the+API

          @EVAL $page = $modx->getObject('modResource', 1);return $page->getTVValue('testing');


          First get the resource whose value you want, then get the TV value from that page for the TV name.
            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
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            You could also use

            @SELECT value FROM modx_site_tmplvar_contentvalues WHERE tmplvarid = 40 AND contentid = 1
              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
              • 37126
              • 37 Posts
              Thanks for the reply. The first option works a treat on localhost but on Windows IIS server still causes a 500 error but strangely nothing in the MODX error log.
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                Well, I don't know anything at all about IIS.
                  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
                  • 37126
                  • 37 Posts
                  Thanks for you help got it working in the end by scrubbing the tvs and recreating them.

                  Still had trouble with @binding in the default value so used a snippet in the end to get the results which seems to work well

                  <?php
                  $tv = $modx->getObject('modTemplateVar', array('name'=>'MyTv'));
                  $val = $tv->getValue($modx->resource->get('id'));
                  if (! empty($val)) {
                  
                  $output = $val;
                  }else{
                  $page = $modx->getObject('modResource', 1);
                  $id = $page->get('id');
                  $tv = $modx->getObject('modTemplateVar',array('name'=>'MyTv'));
                  $val = $tv->renderOutput($id);
                  
                  $output = $val;
                  }
                  return $output;
                  [ed. note: cprookie last edited this post 14 years ago.]
                    • 30485
                    • 7 Posts
                    Hello, is that possible in modx evolution?

                    How to do?
                      • 4041
                      • 788 Posts
                      Quote from: toucas at May 08, 2013, 06:46 PM
                      Hello, is that possible in modx evolution?

                      How to do?

                      This should get you going in the right direction smiley
                      http://wiki.modxcms.com/index.php/API:getTemplateVarOutput
                        xforum
                        http://frsbuilders.net (under construction) forum for evolution