Developer forum

Forum » Development » Adding og: meta tags to news pages

Adding og: meta tags to news pages

Gunnar Johildarson
Reply

Hello,

I am currently working on an extension for NewsV2 on a Dynacmiweb 7 solution. I want to add og: meta tags on news article pages.

I have tried this code, but it does not add anything to the header:

 

 

 

using System;
using Dynamicweb.NewsV2.Extensibility;
using Dynamicweb.Frontend;

namespace DWFacebookNewsExtension
{

    public class AddOgMetaTag : Dynamicweb.NewsV2.Extensibility.NewsItemDetailsTemplateExtender
    {
        const string ogImageMetaTag = "<meta property=\"og:image\" content=\"{0}\"/>";
        const string ogTitleMetaTag = "<meta property=\"og:title\" content=\"{0}\"/>";
        const string ogDescriptionMetaTag = "<meta property=\"og:description\" content=\"{0}\"/>";
        const string ogUrlMetaTag = "<meta property=\"og:url\" content=\"{0}\"/>";

        public override void ExtendTemplate(Dynamicweb.Templatev2.Template t)
        {
            PageView.Current().Meta.Add("image", String.Format(ogImageMetaTag, Item.NewsImage));
            PageView.Current().Meta.Add("title", String.Format(ogTitleMetaTag, Item.NewsHeading));
            PageView.Current().Meta.Add("description", String.Format(ogDescriptionMetaTag, Item.NewsManchet));
            PageView.Current().Meta.Add("url", String.Format(ogUrlMetaTag, Item.NewsLink));
        }
    }
}

 

 

What I am supposed to do, to get DW to render this code?

regards

Gunnar

 

 

 

 

 

 

 

 

 


Replies

 
Nicolai Høeg Pedersen
Reply

 Hi Gunnar

 

Meta class will try to build the meta tag based on the data - you create the entire meta tag.

 

Try calling the PageView.Current().Meta.Add("custom", ...) instead of PageView.Current().Meta.Add("image", ...)

 

That should make the meta data class render your exact meta tag.

 

BR Nicolai

 
Gunnar Johildarson
Reply

Hello Nicolai, 

Can you give a more exact example? I tried to change the code according to your example, but it still does nor render the meta tags.

Is it good enough to compile the new class in to a seperate DLL? Will the system automatically pick it up? Or do I have to make something special, to hook the assembly to the DW rendering engine?

- gunnar

 

 

 

 

 
Nicolai Høeg Pedersen
Reply

Just compile the assembly and put it in /Bin

 

You can debug to see if it is executed. Or call Dynamicweb.Base.w("Being executed") inside your ExtendTemplate method.

 

 

BR Nicolai

 
Gunnar Johildarson
Reply

Well, here is my final solution. The problems in the end turned out to be, that I used News v1! DOH!

using System;
using Dynamicweb.NewsV2.Extensibility;
using Dynamicweb.Frontend;

namespace DWFacebookNewsExtension
{


    public class AddOgMetaTag : Dynamicweb.NewsV2.Extensibility.NewsItemDetailsTemplateExtender
    {
        public override void ExtendTemplate(Dynamicweb.Templatev2.Template t)
        {
            PageView.Current().Meta.Add("og:image", Item.NewsImage);
            PageView.Current().Meta.Add("og:title", Item.NewsHeading);
            PageView.Current().Meta.Add("og:description", Item.NewsManchet);
            PageView.Current().Meta.Add("og:url", Item.NewsLink);
        }
    }
}

And remember the < !--@MetaTags--> in the master template.

- Gunnar

 

 

 

 

 

You must be logged in to post in the forum