Answer the question
In order to leave comments, you need to log in
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
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;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question