Ok, I am making progress with this.
In my snippet I was able to loop through the resources and put the content with the help of calling getChunk() to a variable.
I now would like to remove some content blocks layouts before returning this variable, if they should not be displayed to the visitor. The CB Layout Template chunk contains HTML comments with the country codes it is intended for:
<!--GEO-START--DE-US- -->
content...
<!--GEO-END--DE-US- -->
So my idea was to use preg_match_all to get all commment matches and replace these parts via preg_replace. But it seems that there are no matches found at all. Do I need to convert the variable first to get the regex working?
$output= output of all chunks..
$usergeolocation = "US";
preg_match_all('/<!--GEO-START-(.*?)\-->/ims', $output, $matches);
$usergeolocation = "US";
$mycountryfound = array();
foreach ($matches as $key => $value) {
if (strpos($value, '-'.$usergeolocation.'-') !== false) {
$mycountryfound[] = $key;
}
}
foreach ($mycountryfound as $found) {
$startPoint = $matches[$found];
$endPoint = str_replace("START","END",$matches[$found]);
$output = preg_replace('#('.preg_quote($startPoint).')(.*)('.preg_quote($endPoint).')#si', '', $output);
}
return $output;