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

    at first sorry for my english.

    BTW, i have a problem.

    i use TV with DropDown type where TV populate as name1==1||name2==2||name3==3||. In the page editing interface i see normal select with name1|name2|name3. But in ditto output i see 1|2|3 in that place where i expect value1|value2|valu3 accordingly.

    and now i ask: how tell Ditto to show me name of TV, not value?
      "Und wenn du lange in einen Abgrund blickst, blickt der Abgrund auch in dich hinein."

      Не используйте Revo для "просто сайтов". Используйте Evo

      Who can defeat the Russian bear?
      • 9225
      • 6 Posts
      You don’t find a solution?
      не нашел решения проблемы?
        • 25663 MODX Staff
        • 12,272 Posts
        I believe that Ditto will always return the value. Perhaps you could write a custom phx modifier to return the results you’re seeking?
          Ryan Thrash, MODX Co-Founder
          Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
          • 9225
          • 6 Posts
          With help of heliotrope we made the snippet
          <?php
          $optionvalue = (isset($optionvalue)) ? $optionvalue : false;
          $tvName = (isset($tvName)) ? $tvName : false;
          $prefix = "tv_";
          $phName .= (isset($phName)) ? $phName : $tvName;
          $phName = $prefix.$phName;

          if(!$tvName) return ’erreur pas de tv specicifiee.’;

          if(!function_exists(’getOptionsValue’)){
          function getOptionsValue($tvName){
          global $modx;
          $tblTMP = $modx->getFullTableName("site_tmplvars");
          $where = " name=’".$tvName."’";
          $rs = $modx->db->select(’elements’,$tblTMP,$where,’’,1);
          $row = $modx->fetchRow($rs);

          return $row[’elements’];
          }
          }

          if(!$optionvalue) return;
          //$optionvalue = explode(’,’,$optionvalue);

          if($arrayOptions = $modx->getPlaceholder($phName)){
          $translate = $arrayOptions[$optionvalue];
          }else{
          $elt = getOptionsValue($tvName);
          if(substr($elt,0,5)=="@EVAL"){
          $tmp = eval(substr($elt,5));
          $options = explode(’||’,$tmp);
          }else{
          $options = explode(’||’,$elt);
          }
          $arrayOptions = array();

          foreach($options as $option){
          $attr = explode("==",$option);
          $arrayOptions[$attr[1]] = $attr[0];
          }

          $modx->setPlaceholder($phName),$arrayOptions);
          $translate = $arrayOptions[$optionvalue];
          }

          return $translate;
          ?>

          Usage:
          [[snippet? &tvName=`tvname` &optionvalue=`[+tvname+]` ]]
            • 4385
            • 372 Posts
            Quote from: rthrash at Nov 07, 2007, 10:26 AM

            I believe that Ditto will always return the value. Perhaps you could write a custom phx modifier to return the results you’re seeking?

            Ryan’s idea was easier! Thanks for the pointer. I have a dropdown that displays the title of some documents with the value being the id’s

            So now in my chuck I can build a link with the id and title back to the page.

            phx:docfield

            <?php
                 $field = (strlen($options)>0) ? $options : 'pagetitle';
                 $docfield = $modx->getTemplateVarOutput(array($field), $output, 1);
                 return $docfield[$field];
            ?>


            I will add it to the wiki

            http://wiki.modxcms.com/index.php/PHx/CustomModifiers
              DropboxUploader -- Upload files to a Dropbox account.
              DIG -- Dynamic Image Generator
              gus -- Google URL Shortener
              makeQR -- Uses google chart api to make QR codes.
              MODxTweeter -- Update your twitter status on publish.
              • 6726
              • 7,075 Posts
              Very nice one !
              I have seen this request several times and this will make a few people quite happy grin
                .: COO - Commerce Guys - Community Driven Innovation :.


                MODx est l&#39;outil id
                • 11975
                • 2,542 Posts
                Hi,

                using the getTemplateVarOutput for each document will increase the db query number.
                You should save the value in a placeholder.

                :-)
                  Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
                  • 1634
                  • 51 Posts
                  Quote from: Evil1 at Nov 07, 2007, 10:38 AM

                  With help of heliotrope we made the snippet
                  <?php
                  $optionvalue = (isset($optionvalue)) ? $optionvalue : false;
                  $tvName = (isset($tvName)) ? $tvName : false;
                  $prefix = "tv_";
                  $phName .= (isset($phName)) ? $phName : $tvName;
                  $phName = $prefix.$phName;

                  if(!$tvName) return ’erreur pas de tv specicifiee.’;

                  if(!function_exists(’getOptionsValue’)){
                  function getOptionsValue($tvName){
                  global $modx;
                  $tblTMP = $modx->getFullTableName("site_tmplvars");
                  $where = " name=’".$tvName."’";
                  $rs = $modx->db->select(’elements’,$tblTMP,$where,’’,1);
                  $row = $modx->fetchRow($rs);

                  return $row[’elements’];
                  }
                  }

                  if(!$optionvalue) return;
                  //$optionvalue = explode(’,’,$optionvalue);

                  if($arrayOptions = $modx->getPlaceholder($phName)){
                  $translate = $arrayOptions[$optionvalue];
                  }else{
                  $elt = getOptionsValue($tvName);
                  if(substr($elt,0,5)=="@EVAL"){
                  $tmp = eval(substr($elt,5));
                  $options = explode(’||’,$tmp);
                  }else{
                  $options = explode(’||’,$elt);
                  }
                  $arrayOptions = array();

                  foreach($options as $option){
                  $attr = explode("==",$option);
                  $arrayOptions[$attr[1]] = $attr[0];
                  }

                  $modx->setPlaceholder($phName),$arrayOptions);
                  $translate = $arrayOptions[$optionvalue];
                  }

                  return $translate;
                  ?>

                  Usage:
                  [[snippet? &tvName=`tvname` &optionvalue=`[+tvname+]` ]]

                  Well that is a wonderful bit of code that saved me a job, thank you indeed. There is, however an error in the code on line 42.

                  This:

                  $modx->setPlaceholder($phName),$arrayOptions); 
                  


                  Should read this:

                  $modx->setPlaceholder($phName,$arrayOptions); 
                  


                  That is all. Cheers.
                    Hmmmmm.

                    It&#39;s all a delusion
                    • 7231
                    • 4,205 Posts
                    @andyflan: what does this do? I was unable to figure out what this snippet does. rolleyes
                      [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                      Something is happening here, but you don&#39;t know what it is.
                      Do you, Mr. Jones? - [bob dylan]
                      • 11975
                      • 2,542 Posts
                      Hi,

                      the aim of the snippet is to display the name of tv options (Oui==1||Non==2)
                      [*tv*] will return 1 or 2 but If you’d like to display Oui or Non you need the snippet above.


                      I’ve written another piece of code based on tvEditor class to make the same result but with better support of @BINDINGS in tv elements.
                      As it is a phx modifier you can use it in any case.

                      :-)
                        Made with MODx : [url=http://www.copadel.com]copadel, fruits et l