Untitled
checktommydalton
twig
a year ago
1.7 kB
4
Indexable
{# Initialize an array to hold the SEOmatic results #} {% set seomaticFilteredResults = [] %} {# Iterate over all entries to check SEOmatic fields if they exist #} {% for entry in craftResults %} {% if entry.seo is defined and entry.seo.metaGlobalVars is defined %} {% set seoTitle = entry.seo.metaGlobalVars.parsedValue('seoTitle') %} {% set seoDescription = entry.seo.metaGlobalVars.parsedValue('seoDescription') %} {% set modifiedSlug = entry.slug|replace({'-': ''}) %} {# Check if the query matches any of the SEOmatic fields or modified slug #} {% if props.query in seoTitle or props.query in seoDescription or props.query in modifiedSlug %} {% set seomaticFilteredResults = seomaticFilteredResults|merge([entry]) %} {% endif %} {% endif %} {% endfor %} {# Combine and remove duplicates #} {% set combinedResults = craftResults|merge(seomaticFilteredResults) %} {% set uniqueResults = [] %} {% set seenIds = [] %} {% for entry in combinedResults %} {% if entry.id not in seenIds %} {% set uniqueResults = uniqueResults|merge([entry]) %} {% set seenIds = seenIds|merge([entry.id]) %} {% endif %} {% endfor %} {# Output the results #} {% for entry in uniqueResults %} <div class="col px-0 h-100 mb-6"> <h5 class=""><a href="{{ entry.url }}">{{ entry.title }}</a></h5> {% if entry.seo is defined and entry.seo.metaGlobalVars is defined and entry.seo.metaGlobalVars.parsedValue('seoDescription')|length %} <div class="redactor">{{ entry.seo.metaGlobalVars.parsedValue('seoDescription') ?? '' }}</div> {% endif %} </div> {% endfor %}
Editor is loading...
Leave a Comment