nystudio107 / craft-seomatic

SEOmatic facilitates modern SEO best practices & implementation for Craft CMS 3. It is a turnkey SEO system that is comprehensive, powerful, and flexible.
https://nystudio107.com/plugins/seomatic
Other
166 stars 71 forks source link

Access the metadata of one entry from another entry #1504

Closed watchwood closed 2 months ago

watchwood commented 3 months ago

Is there a way to access the metadata of one entry from another entry?

I'm trying to set up a lander page using the SEO summaries from child entries as the page descriptions, and I can't find a way to do it.

khalwat commented 2 months ago

You can use seomatic.helper.loadMetadataForUri ():

https://nystudio107.com/docs/seomatic/using/helper-functions.html#helper-functions

Roughly something like:

{% do seomatic.helper.loadMetadataForUri(childEntry.url) %}
{# The various SEOmatic variables will now be populated with the right metadata #}
{{ seomatic.meta.description }}
{# Set it back to the actual entry so that the correct metadata loads for this page #}
{% do seomatic.helper.loadMetadataForUri(entry.url) %}

This is also detailed more in the following article:

https://nystudio107.com/blog/tips-for-using-seomatic-effectively#rendering-metadata-from-another-route