Answer the question
In order to leave comments, you need to log in
How to organize the display of a value of the type "list of resources" in the Collections snippet?
Good afternoon! The object category is set to the material type Collection. In the columns I indicate the TV fields. Those that have input type "list of resources" or checkboxes (selects) with possible values of type value1==1||value2==2||.. are displayed as numbers - for a list of resources, this is the resource id or keys for a multiselect respectively.
Who worked with this snippet, tell me how to write a friendly output of meaningful values?
I myself work with this snippet for the first time, I did not find such a solution in the open spaces of the network.
Answer the question
In order to leave comments, you need to log in
The solution was found independently.
After digging into the documentation, I found out that Collections provides the ability to process a value with render snippets.
For my needs, I wrote two types of snippets.
If in the Collections view you need to display the value of a field with the input type "list of resources" and you need to display the pagetitle of the resources, and not their id, you can use the following code:
<?php
$value = $modx->getOption('value', $scriptProperties, '');
$res = $modx->getObject('modResource',$value);
$output = $res->get('pagetitle');
return $output;
<?php
$inputValue = $modx->getOption('value', $scriptProperties, '');
$resourceQuery = new xPDOCriteria($modx, "SELECT * FROM {$modx->getTableName('modTemplateVar')} WHERE name = 'objectTip'");
$tv = $modx->getObject('modTemplateVar', $resourceQuery);
$elements = $tv->get('elements');
$options = explode('||', $elements);
$lookup = array();
foreach ($options as $o) {
list($name, $value) = explode('==', $o);
$lookup[$value] = $name;
}
$output = $lookup[$inputValue];
return $output;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question