I have a TV multi select list type that is evaluating a snippet:
@EVAL return $modx->runSnippet('getFeaturedResourceTree');
Evaluating this snippett:
<?php
$output = array();
$context = $modx->resource->get('context_key');
$sql = "select * from modx_site_content where context_key = '$context' order by `pagetitle`;";
$results = $modx->query($sql);
foreach($results as $result){
$output[] = $result['pagetitle'].'=='.$result['id'];
}
$output = implode('||', $output);
echo $output;
return;
This does work in the manager, I can select and pick multiple resources in the list. However, when I save the TV, nothing is actuially saved. the TV values are not present in the database and when I reload the resource, the TV field is blank.
what could the problem be here?
I'm fairly certain you can accomplish what you're trying to do with an @SELECT
binding rather than @EVAL
. This has 2 potential benefits:
@EVAL
is Evil, LOL. Not all the time, mind you—there are certainly legitimate uses of @EVAL
but I've personally always tried very hard to find an alternative, whenever I've considered using @EVAL
. The method I'm about to show you has worked for me in the past, so I'm speculating it will work for you.
@SELECT pagetitle, id FROM modx_site_content WHERE context_key = 'web' ORDER BY `pagetitle`
If you're using @EVAL
because you have multiple contexts and you want the context of the Resource currently being edited, then you could use your Snippet, but I would try:
@CHUNK
binding.One more note: I can't remember if the current Resource is available in the TV as $modx->resource
or $resource
, but that might be something you want to double check.