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

    I can't figure out, how to display all input values for specific TV (type single listbox).

    My TV input is:
    a||b||c||d||e


    Now I need to display all the values (not the selected / assigned to template) as a dropdown menu (which isn't the problem yet).
    • The modTemplateVar object has a getInputOptions method that you should be able to use in a snippet. Use the $modx->getObject('modTemplateVar',$criteria) function to get the particular TV object you're interested in. Perhaps something like this would give you an array of options to work with:
      $myTV = $modx->getObject('modTemplateVar', $tvID);
      $options = $myTV->getInputOptions();
        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
        • 3943
        • 8 Posts
        Thank you smiley I wasn't aware of the modTemplateVar object.

        Finally i made the script as following:
        $tvname = $scriptProperties['tvname'];
        $output = "";
        
        $tv = $modx->getObject('modTemplateVar',array('name'=>$tvname));
         
        $elements = $tv->get('elements');
        $items = explode('||', $elements);
        
        foreach ($items as $item) {
          $output .= "<option>$item</option>";
        }
        
        return $output;


        Unfortunately, this
        $options = $myTV->getInputOptions();
        gave me an error but after more searching I found the correct way smiley

        The
        elements
        is the actual column name in
        modx_site_tmplvars
        , holding all values of specified TV.