Hello,
I’m trying to create a snippet that highlights specific words for a heading field in ContentBlocks.
Here is what the field looks like in the front-end:
In this example “About” should get a yellow highlight which works.
However, I want the user to be able to select the color of the highlight, hence the setting “Highlight color”.
The ContentBlocks field looks like this:
<[[+level]]>[[+value:addHeadingHighlight]]</[[+level]]>
And the snippet looks like this:
<?php
$input = $modx->getOption('input',$scriptProperties,'');
$highlight = $modx->getOption('highlight',$scriptProperties,'');
// Search for matches within the input
preg_match_all('/##[^##]+##/', $input, $result);
// Loop trough the results and place the underline.
foreach($result[0] as $res) {
$input = str_replace($res, '<span class="'.$highlight.'">'.str_replace('#', '', $res).'</span>', $input);
}
// Return the string
return $input;
Is it possible to retrieve the “Highlight color” setting in this snippet?
I did find the cbGetFieldContent snippet, however I don’t think it’s possible to use this within the setting to apply the correct class to the heading.
I’ve also tried searching the internet and reading through the ContentBlocks docs, but unfortunately I couldn’t find anyone who had the same issue (perhaps I’m searching for something obvious ).
Any help would be appreciated!
Thomas