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?
You don’t find a solution?
не нашел решения проблемы?
-
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
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.
Very nice one !
I have seen this request several times and this will make a few people quite happy
.: COO - Commerce Guys - Community Driven Innovation :.
MODx est l'outil id
Hi,
using the getTemplateVarOutput for each document will increase the db query number.
You should save the value in a placeholder.
:-)
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's all a delusion
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.
:-)