Take the 2-minute tour ×

I am working on an EPiServer 5 project and I need to fill in the meta-description property of my page type with data from other properties. E.g. Take the first sentence of the body and use it as meta description"

This should be done if the editor left the meta description empty. Any help on how to solve this issue?

Many thanks.

share|improve this question

2 Answers 2

up vote 2 down vote accepted

There is a code example how to fallback and extract text from your main body in the example project PublicTemplates (or Alloy demo site for EPiServer 6 R2 and later) that ships with EPiServer. Look at the Header.ascx.cs file.

share|improve this answer
Thanks for the help Fredrik, I wIll give take a look right away. –  tif Mar 30 '11 at 11:20
I checked at the code and is similar to the solution I developed. The question I have atm is if there is a better solution for this. I mean that if it would be better to generate this meta-description at the time of saving the page, then we would avoid generating the meta-descriptions each time a page is loaded (if it has not meta-description of course). Would this be a better solution? –  tif Mar 30 '11 at 11:31
Yes, you would win a little performance to compute the value for meta description when you save the page but that is probably a premature optimization. Extracting some text from a HTML property is probably a small task compared to all other things happening when rendering a page. A simple solution, force the editors to write a meta description by setting the page property for meta description to be required. –  Fredrik Haglund Apr 4 '11 at 13:00

Connect to the DataFactory PageSave event and change the value before it is saved.

share|improve this answer
Thanks for the reply Mattias. Just not sure how to achieved this. Do I need to go to the code behind of my template? Do I need to do this for each page type? If you could explain it with a bit more of detail would be appreciated. Cheers. –  tif Mar 30 '11 at 6:51

Your Answer


