We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1526
    • 72 Posts
    I'd like to ouput a list ov TV values with their caption as titles. Is this possible? How? and what if it is multilanguage with YAMS? something like:
    <li title="[[howDoIgetmyTVCaption?]]">[[YAMS? &get=`tv` &from=`myTemplateVariable`]]</li>

    (or eventually the same in a table)
    thank you

    [edit] I'm getting close, but...
    I put this call in my page:
    [[getTvCaption? &wichTV=`[[YAMS? &get=`tv` &from=`workTechnique`]]`]]

    where YAMS? &get=`tv` &from=`workTechnique` should be workTechnique_en and the getTvCaption snippet is:
    <?php
    $tvCaption = $modx->db->getValue( $modx->db->select( 'caption', $modx->getFullTableName('site_tmplvars'), 'name='.$wichTV ));
    //return $wichTV;
    return $tvCaption;
    ?>

    I get this error:
    « Execution of a query to the database failed - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[[YAM'... at line 1 »
    SQL: SELECT caption FROM `isabella_modx`.`modx_site_tmplvars` WHERE name=[[YAM ...
    I had to study the database tables, of course, and I was expecting that the query should be translated from modx to mysql to retrive the value in the column 'caption' where the corresponding value in the 'name' column is "workTechnique_en". Of course to debug I tryied to use the value 'workTechnique_en' in the query in place of the variable '$wichTV', getting the similar error
    « Execution of a query to the database failed - Unknown column 'workTechnique_en' in 'where clause' »
    SQL: SELECT caption FROM `isabella_modx`.`modx_site_tmplvars` WHERE name=workTechnique_en
    while, if I change the end of the snippet to
    ...'name='.'name'

    i get the value of the first 'caption' of the table.
    if I just put "return $wichTV;" it gives me its right YAMS value (workTechnique_en).

    Quite confused, am I? sad
    to summarize:
    1. where's the error in my query? (+is there any tutorial online?)
    2. is that the right way to pass a yams ouput to the snippet?

    Thank you
    [ed. note: andrearicci last edited this post 14 years, 10 months ago.]
      MODx evo 1.5~1.6 ✪ Apache v 2.2.22 ✪ PHP v 5.3.10 ✪ MySQL v 5.1.61
      <°'iiii);
      • 16278
      • 928 Posts
      I know nothing of Yams, but I do know you can obtain the definition of a TV using the API, rather than a database call:
      <?php
      $tvDef = $modx->getTemplateVar($tv, 'caption');
      return $tvDef['caption'];
      ?>

      ;)
        • 1526
        • 72 Posts
        thank you very much.
        Looks so simple.
        Wich is the best palce to learn the APIs?
          MODx evo 1.5~1.6 ✪ Apache v 2.2.22 ✪ PHP v 5.3.10 ✪ MySQL v 5.1.61
          <°'iiii);
          • 16278
          • 928 Posts
          I usually refer to the old Wiki:
          http://wiki.modxcms.com/index.php/Category:API

          :) KP