Developer forum

Forum » Development » Meta keywords set with API

Meta keywords set with API

Lars Larsen
Lars Larsen
Reply

Hi

Is it possible and if so how to set the meta keywords on a page with the API?


Replies

 
Lars Larsen
Lars Larsen
Reply

Bump!

 
Nicolai Pedersen
Reply

Where from?

Page.Keywords is one option: https://doc.dynamicweb.com/api-docs#article=28063288-5739-d758-4a05-7e53d73e99a3

PageView.Meta is another option.

Depends on what you need it for.

I do not think we render keywords to the frontend anymore as it is kind of deprecated...

 
Lars Larsen
Lars Larsen
Reply

Hi Nicolai

I am not sure I get what you mean by "Where from?". I just want to overwrite the meta keywords tag in the markup.

I have tried adding these lines to the master template:

PageView.Meta.AddTag("keywords", "my special keywords")

That didn't render my keywords. So have also tried:

Dynamicweb.Content.Page page = Pageview.Page;
page.Keywords = "my special keywords";
 
But no luck here either.
 
Nicolai Pedersen
Reply
This post has been marked as an answer

Because it has meaning... You are setting the value too late in the rendering.

The master template is what is rendering the meta data - so adding things to the meta data in that template is a little too late, see this thread from today:

https://doc.dynamicweb.com/forum/cms-standard-features?ThreadID=74365

As a side note, using meta keywords these days...? For what reason?

Votes for this answer: 1
 
Lars Larsen
Lars Larsen
Reply

Got it working by doing it this way:

    public class PageLoaded : NotificationSubscriber
    {
        public override void OnNotify(string notification, NotificationArgs args)
        {
            Standard.Page.LoadedArgs loadedArgs = args as Standard.Page.LoadedArgs;

            loadedArgs.PageViewInstance.Meta.AddTag("keywords", "my special keywords");
        }
    }

Thanks Nicolai smiley

 

You must be logged in to post in the forum