Developer forum

Forum » CMS - Standard features » Add option for AddOpenGraphTag to avoid overwriting existing values

Add option for AddOpenGraphTag to avoid overwriting existing values

Anders Ebdrup
Reply

Hi Dynamicweb,

Would it be possible to add an overload or similar option to AddOpenGraphTag, so it can be used as a fallback without overwriting values that have already been set by a module or template?

In Swift’s master template we currently have this section:

Pageview.Meta.AddOpenGraphTag("type", "website");
Pageview.Meta.AddOpenGraphTag("url", Pageview.Meta.Canonical?.ToString());
Pageview.Meta.AddOpenGraphTag("title", Model.Title);
Pageview.Meta.AddOpenGraphTag("description", Model.Description);

This works well for default Open Graph metadata, but it also means that values set earlier by a module or custom template can be overwritten. For example, a product module or detail template may set a more specific og:title or og:description, but the master template then replaces it with the page-level fallback value.

Could an overload be added, for example:

Pageview.Meta.AddOpenGraphTag("title", Model.Title, overwrite: false);

That would allow Swift’s master template to define safe fallback values while still respecting more specific Open Graph tags from modules and templates.

Best regards,

Anders


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply
This post has been marked as an answer

I have added the overload - the call in master needs to change though. https://doc.dynamicweb.dev/documentation/fundamentals/dw10release/releasenotes/workiteminfo.html?workitemid=28896

If you change Dynamicweb.Frontend.PageView.Current().Meta.Title instead, you overwrite what comes from the page it self. But then og:title and <title> cannot be different.

Votes for this answer: 1
 
Anders Ebdrup
Reply

Nice, thank you, Nicolai!

 

You must be logged in to post in the forum