highlight
string | highlight: string
returns string
Wraps all instances of a specific string, within a given string, with an HTML <strong> tag with a class attribute
of highlight.
{% for item in search.results %}
{% if item.object_type == 'product' %}
{{ item.description | highlight: search.terms }}
{% else %}
{{ item.content | highlight: search.terms }}
{% endif %}
{% endfor %}
Code
{% for item in search.results %}
{% if item.object_type == 'product' %}
{{ item.description | highlight: search.terms }}
{% else %}
{{ item.content | highlight: search.terms }}
{% endif %}
{% endfor %}Data
{
"search": {
"results": [
{
"description": "",
"object_type": "product"
},
{
"description": "",
"object_type": "product"
},
{
"description": "",
"object_type": "product"
},
{
"description": "",
"object_type": "product"
},
{
"description": "This is a love potion.",
"object_type": "product"
},
{
"description": "",
"object_type": "product"
}
],
"terms": "love"
}
}Output
This is a <strong class="highlight">love</strong> potion.
Output
This is a <strong class="highlight">love</strong> potion.Was this page helpful?