• How to use templatevar output in snippet#

  • opengeek Reply #1, 6 years, 8 months ago

    Reply
    I'm trying to use the @SQL binding in a TV, then retrieve and use the associative array results in a snippet like such:

    if (!isset($id)) { $id = $modx->documentIdentifier; }
    $docInfo = $modx->getDocument($id);
    $alias = $docInfo['alias'];
    
    $out = "";
    
    $tv = $modx->getTemplateVarOutput(array("industries"), $id);
    $results = $tv["industries"];
    if (is_array($results))
    {
    foreach ($results as $key=>$val)
    {
    $href = $modx->makeURL($id, $alias, "i=$key");
    $out .= "<a href='$href' title='$val'>$val</a>\n";
    }
    }
    
    return $out;


    However, the output I'm getting from this is simply the TV definition:

    <a href='index.php?id=14i=0' title='industries'>industries</a>
    <a href='index.php?id=14i=1' title='@SELECT id,name FROM industries ORDER BY name ASC'>@SELECT id,name FROM industries ORDER BY name ASC</a>
    <a href='index.php?id=14i=2' title=''></a>
    <a href='index.php?id=14i=3' title=''></a>
    <a href='index.php?id=14i=4' title='text'>text</a>


    This appears to be because of this line in document.parser.class.inc.php:

    $curDoc = false; // temporary hack to make it work ... Ryan Thrash 


    ...which is preventing me from getting the formatted TV output? Seems to be a temporary hack to keep it from working.


  • xwisdom Reply #2, 6 years, 8 months ago

    Reply

    That could be true opengeek If it is then just remove it and let me know.

    Thanks


  • opengeek Reply #3, 6 years, 8 months ago

    Reply
    Quote from: xwisdom at May 30, 2005, 03:48 PM

    That could be true opengeek If it is then just remove it and let me know.

    Thanks


    Unfortunately, I tried using the real value and hardcoding it to true and still could not get it to go through the getTVDisplayFormat() function.


  • xwisdom Reply #4, 6 years, 8 months ago

    Reply
    Ok, try modifying the for loop inside the getTemplateVarOutput function to read:
    for($i=0;$i<count($result);$i++) {
    	$row = $result[$i];
    	$output[$row['name']] = getTVDisplayFormat($this,$row['name'],$row['value'],$row['display'],$row['display_params'],$row['type']);
    }


    Give it a try