Using the tutorial "
Create TV-Based Chunks", I set up a template where you can choose an agent to associate with a property listing. Some properties will feature multiple agents, so I used a checkbox to allow for more than one agent using the TV-Based Chunk. Everything works great, until I am formatting my search results (using tvExplorer) page and attempting to display the Agent. The TV-Based Chunk snippets require using a , delimiter, which means when there is more than one agent selected, then there is no space after the comma. If I try to add a non-breaking space to the delimiter, then the subsequent TV-Based chunks won’t show up (but the first one works fine). I was trying to modify the snippet code to add a space and then change the delimiter in the TV, but neither seem to work. Also, it seems to be affecting my searches as well. If there is the space there, then neither agent (first or second) will show up in the results even when I am searching for them specifically.
If someone could point out if it’s possible for me to change the delimiter without breaking the functionality and how to do it, I would be extremely grateful! Ideally, I’d like to use a break tag
, but if I can do Agent1, Agent2 instead of Agent1,Agent2, that would work too!
getChunk snippet
<?php
$q_chunks = $modx->db->query('
SELECT
chunk.*
FROM '.$modx->getFullTableName('site_htmlsnippets').' AS chunk
INNER JOIN '.$modx->getFullTableName('categories').' AS category
ON chunk.category = category.id
WHERE
category.category IN ("'.$category.'")
ORDER BY
name
');
$ar_chunks = array();
while ($row = $modx->db->getRow($q_chunks)) {
$ar_chunks[] = $row['name'];
}
$l_chunks = implode("||",$ar_chunks);
return $l_chunks;
?>
chunkListParser snippet
<?php
$ar_chunks = split(',',$chunks);
$ar_chunks = array_unique($ar_chunks);
$output = '';
foreach ($ar_chunks as $chunk) {
if ($chunk != '') {
$c = $modx->getChunk($chunk);
if ($c) $output .= $c;
}
}
if ($output != '' && isset($wrapperdiv)) {
$output = '<div id="'.$wrapperdiv.'">'.$output.'</div>';
}
return $output;
?>