Snippet: Template logic to fetch using an attribute filter using the like condition

We have seen this question asked many times and wanted to ensure this question is simpler to answer in the future

Question

How exactly do you use an attribute filter using the like condition?

Solutions

These solutions have been tested but may not be generic, so some modifications to ids etc may be required.

Filter by Class/Attribute Identifier

{def $c=fetch( 'content', 'tree', hash( 'parent_node_id', 175,
               depth, 7,
               attribute_filter, array( array( 'article/keywords', 'like', '*string*' ) )
               ) )}
 
{$c|attribute(show,1)}
{$c.0|attribute(show,1)}
 

Filter by Attribute ID

{def $c=fetch( 'content', 'tree', hash( 'parent_node_id', 175,
                depth, 7,
                attribute_filter, array( array( 865, 'like', '*string*' ) )
                ) )}
 

Filter by dynamic string variable

{def $tag='string'}
{def $c=fetch( 'content', 'tree', hash( 'parent_node_id', 175,
                depth, 7,
                attribute_filter, array( array( 'article/keywords', 'like', concat( '*', $tag, '*' ) ) )
                ) )}
 

Warning

Be certain to clear cache or disable cache!

References