Untitled
count matchestommydalton
twig
a year ago
705 B
7
Indexable
{% set query = props.query %} {% set description = entry.seo.metaGlobalVars.parsedValue('seoDescription') ?? '' %} {# Split the description by the query to count occurrences #} {% set occurrences = description|split(query) %} {# Subtract 1 from the total split parts to get the match count #} {% set matchedCount = (occurrences|length > 0) ? occurrences|length - 1 : 0 %} {# Check if there's at least one match #} {% if matchedCount > 0 %} {# Set the matched content #} {% set matchedContent = query %} {# Output the count and the HTML with the matched content #} <div>Displaying {{ matchedCount }}</div> <div>{{ entry.id }}: {{ matchedContent }}</div> {% endif %}
Editor is loading...
Leave a Comment