Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Adding MetaTag from a Transformation View modes: 
User avatar
Member
Member
dantahoua-gmail - 1/27/2012 3:29:15 PM
   
Adding MetaTag from a Transformation
Hello.
I'm stuck here. I would like to add specific metatag in my header regarding a news (for facebook like button). I want to add the famous "
<meta property="og:tag name" content="tag value"/>
in the header from the transformation I use in my repeater.
I tried to make a function with
Page.Header.Controls.Add(new LiteralControl("<meta name=\"og:description\" content=\"aaaatest\" />"));
but it doesn't work (tell me that I can't use page in a static function...).
If you could help me, would be great!
Thanks.

User avatar
Kentico Consulting
Kentico Consulting
kentico_mirekr - 1/28/2012 8:38:49 PM
   
RE:Adding MetaTag from a Transformation
Hi,

here is an code example that you can use in transformation:

<script runat="server">
protected override void OnPreRender(EventArgs e)
{
this.Page.Header.Controls.Add(new LiteralControl("<meta name=\"og:description\" content=\"aaaatest\" />"));
}
</script>


Hope that this helps.

Thanks,
Miro

User avatar
Member
Member
dantahoua-gmail - 1/29/2012 9:31:48 AM
   
RE:Adding MetaTag from a Transformation
Thanks. Will I be able to use the <%# GetDocumentUrl() %> or the <%# Eval("NewsTitle") %> kind of method in that protected overrided method? I'm not sure? Cause I need to have access to the transformation property to put them in the meta like
<meta name="og:title" content-" <%# Eval("NewsTitle") %>" >.
Thanks.

User avatar
Member
Member
dantahoua-gmail - 2/6/2012 3:28:27 PM
   
RE:Adding MetaTag from a Transformation
If someone need to know, I use this code for adding Facebook "og" metatag:
<script runat="server">
protected override void OnInit(EventArgs e) {
this.Page.Header.Controls.Add(new LiteralControl("<meta property=\"og:title\" content=\"" + Eval("BlogPostTitle").ToString() + "\" />"));
}</script>

Work great!