Browser: Chrome 110
OS: macOS
URL: Template Test with Image Element using dynamic data tag
The content for dynamic tag used for the source in Image Element does not output the correct values.
Expected: //example.com
Actual: {
Tried:
https://example.com
→ outputs{
//example.com
→ outputs{
['//example.com']
Fatal Error: str_pos() expects a string, array given
The dynamic tag does appear to work since I have tried it with in the link section and the value shows up in the href attribute. The image processing code has a few areas where the issue could be but I can’t step through on the server and I don’t have an environment setup locally for this project to determine where it is that {
is showing up. I suspect that it might be where it explodes for tag arguments but that doesn’t actually appear to be the case.
Even having {ns_my_thumbnail:url}
does not appear to do change anything.
Created the dynamic tag:
add_filter( 'bricks/dynamic_tags_list', 'add_bricks_dynamic_tags' );
add_filter( 'bricks/dynamic_data/render_tag', 'tag_value', 10, 3 );
add_filter( 'bricks/dynamic_data/render_content', 'render_thumbnail_tag', 10, 3 );
add_filter( 'bricks/frontend/render_data', 'render_thumbnail_tag', 10, 2 );
function tag_value( $tag, $post, $context = 'text' )
{
// $tag is the tag name without the curly braces
if ( $tag !== 'ns_my_thumbnail' ) {
return $tag;
}
tag_setup();
return 'Thumbnail';
}
function add_bricks_dynamic_tags( $tags )
{
$tags[] = [
'name' => '{ns_my_thumbnail}',
'label' => 'Thumbnail',
'group' => 'Product',
];
return $tags;
}
function render_thumbnail_tag( $content, $post, $context = 'text' )
{
// $content might consists of HTML and other dynamic tags
// Only look for dynamic tag {my_dd_tag}
if ( ! str_contains($content, '{ns_my_thumbnail}') ) {
return $content;
}
tag_setup();
$content = str_replace( '{ns_my_thumbnail}', '//example.com', $content );
return $content;
}
function tag_setup() { }
I discovered this on Bricks 1.7.2 and upgraded to 1.8.6 and the problem still persists. It could be a skill issue but I tried returning various values with no change. It is weird as it seems that the filter expects an array from tag_value()
or from render_thumbnail_tag()
but providing an array errors.
$images = $this->render_dynamic_data_tag( $image['useDynamicData'], 'image', [ 'size' => $image['size'] ] );
if ( ! empty( $images[0] ) ) {
if ( is_numeric( $images[0] ) ) {
$image['id'] = $images[0];
} else {
$image['url'] = $images[0];
}
}
This code from image.php lines 631-639 appear to be suspect. It shouldn’t be a PHP version issue as I believe PHP 8.1 still supports accessing a string position using array brackets. /
or h
should not be empty. I was thinking tag_value()
would require the link to be returned but that doesn’t appear to be the case either. Even if it did, it still does not explain why other dynamic tag values work, including the same dynamic tag elsewhere. I haven’t been able to even confirm that this is the area without stepping through.