A
A
ADMIN INDIGO2019-10-14 13:31:12
MODX
ADMIN INDIGO, 2019-10-14 13:31:12

How to get a key from tv in modx?

There is TV for example
with similar values:
Vasya==1||Petya==2||Kolya==3||Olya==4, etc.
when trying to display the standard in a chunk, we get a stupid number, i.e. what is after "==", how to get what is before "=="?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
ADMIN INDIGO, 2019-10-14
@INDIGO1

Here is the answer given on the forum in modx (I didn’t try to do it myself because I solve the problem differently)
Make a snippet:

<?php
if(!$tv = $modx->getObject('modTemplateVar', $tvid)) return;
$el = explode('||', $tv->get('elements'));
foreach($el as $item){
   if(explode('==', $item)[1] == $value) $out = explode('==', $item)[0];
}
return $out;

Output:
[ [Snippet?
&tvid=`12` //TV ID
&value=`3` // Value
] ]
You have TV value: 1,2,3 or 4.
If &value=`3`, then Kolya will be displayed, if 4, then Olya .
If necessary, in accordance with a specific resource, then not on its page like this:
&value=`[ [*tvname] ]`
If in chunks, then like this:
&value=`[ [+tv.tvname] ]`

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question