SaaS CMS has officially launched! Learn more now.

Autogenerate Meta-Description Tag from Body Property when left empty


Hi, I am trying to autogenerate the content for the meta-description property on my Page Type with the fist sentences of the Body Property content. This will ocurr if the meta description property was left empty. 

I achived this by adding some code to the master page to collect the text from the property and add a meta-description tag to the page. 

But this is probably not the optimal way to solve this issue. My first thought is that if I can do this at the time of saving a new page, this means taking the desired text and actually saving it in the meta-description property would be a better solutiion. At least I would not need to call my function to generate the tag everytime a page is loaded. 

Any thoughts on how to achive this and would it have to be made for every single page template file?


Mar 30, 2011 10:19

I would go with the approach you are using at the moment. Otherwise the content on the page can change without the meta description being resaved. If you still want to do it the other way you can attach an event to DataFactory.Instance.PublishingPage and work you magic there.

Mar 30, 2011 11:55

Hi Erik, thanks for the reply. I will stick with the current solution since the second one has the problem of keeping the text up to date.


Mar 30, 2011 13:39

If you are doing some very heavy processing on the text (which I doubt you are) you could cache the processed context with a cache dependency to the PageData (call DataFactoryCache.CreateDepencency to get a dependency to use) and you'd probably improve performance while making sure the meta description is updated when the page is.

Mar 30, 2011 15:10

As you mention I am not doing any heavy processing on the text. Thanks for the tip Magnus.

Mar 30, 2011 16:01
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.