Developer forum

Forum » CMS - Standard features » Override MetaTitle and MetaDescription from Page Template

Override MetaTitle and MetaDescription from Page Template

Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi guys,

I have an old project using DW 9.6.12 with a template set using RazorTemplateBase<RazorTemplateModel<Template>>

I am trying to override the values for MetaTitle and MetaDescription from the Page template.

I have tried every solution I have found in the community (including solutions to some of my older posts) but nothing works. Maybe I am just tired :)

I have tried with data-settings="disableparsing:true;" and without it, the values are not overwritten. Even worse, if I remove that part, I get a nasty yellow error:

Node "<title></title>" was not found in the collection
Parameter name: node

Can somebody suggest a working solution?

Thank you,

Adrian


Replies

 
Mario Santos Dynamicweb Employee
Mario Santos
Reply

Hi Adrian,

Have you tried the following? I have it in an old solution (DW8)
Pageview.Meta.Title = "value";

BR, Mario

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Mario,

Thank you for the reply.

I have already tried it.

Actually, this solution is based on an old Rizzo code :)

I have tried:

Pageview.Meta.Title="value";

Pageview.Meta.Add("title","value")

Pageview.Meta.AddTag("title","value")

Pageview.Meta.AddTag("customtitle","value")

Dynamicweb.Frontend.PageView.Current().Meta.Title

And a few other combinations.

One of them should have worked as I have done this type of change a couple of times already.

I will probably have to start from scratch with a fresh approach on it.

Thank you,

Adrian

 

 
Nicolai Pedersen
Reply

You cannot override the title in the template. Because the template is rendering the pageview, so it is too late.

You have a execution something like this 

  1. Pageview created
  2. Content executed
    1. With modules
  3. Render the pageview with content - all values from the pageview are now put into a template instance in its tag collection. Modifying anything in the pageview after this, will not affect rendering...
  4. Now in the layout template - nothing can be changed on the obects after they are rendered.
  5. When you are rendering i.e. the body, you can set pageview.meta.title, but it will have no effect because it was already rendered
  6. OnAfterOutput notification - here you can change the output of the rendering

So you have to set it some code in 1+2 or in 6

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,

It makes total sense. I remember that I was able to change the values from Cart module. which is in Step 2 from your flow (if I understand correctly).

I have noticed though that using Snippets might work although I am not sure if this would have any performance impact.

Thank you,
Adrian

 

 
Nicolai Pedersen
Reply

Snippets are post processing thing. So after step 6, snippets are moved around.

And yes - it has a performance hit of parsing and moving things around. You can see that in debug=true. It should be minor unless your response markup is large.

BR Nicolai

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,

Thank you for the clarification. The markup is pretty slim. it should not affect the performance.

Thank you,
Adrian

 
Hans Ravnsfjall
Hans Ravnsfjall
Reply

hi

 

Does this mean that it is not possible to set a meta-title from inside a paragraph containing product catalogue? That is the only location where i have the value i want to set as page meta title.

 

/Hans

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Hans,

You are right, you cannot set it from PageTemplate or Paragraph template.

You can set it from the Module. I have made several attempts and then Nicolai explained the order of how the different parts are processed and I always try to get my values in the Module instead of the Paragraph. Snippets can work in some situations but I have tried to avoid Shippets because of the performance hit. 


Adrian

 

 
Hans Ravnsfjall
Hans Ravnsfjall
Reply

Ok, thank you very mutch Ardian 👍🏻

/Hans

 
Nicolai Pedersen
Reply

When running a product catalog, the title of a group page is set by the module if you fill out the title field on the product group.

The same goes for a product detail page.

Both groups and products have a title field for this.

 

You must be logged in to post in the forum