Developer forum

Forum » Templates » Description meta tags

Description meta tags

Davor Zlotrg
Reply

Hi DynamicWeb,

I am trying to render meta tags for description, keywords in my Master. I would like to pull existing data from page properties from Admin.

First issue that I confronted is that when I put description meta tag in head section like below (with all lower case letters) it wont render at all in HTML:

<meta name="description" content="...." />

How can i get meta tags from PageView object?

I tried something similiar like this @Dynamicweb.Frontend.PageView.Current().Meta.Title but with no success.

Also I tried using PageTemplateExtender to get meta tags from page but could not find a way. As I can see there is only method for adding custom tags:

     this.PageView.Meta.Add("description", "test description");

Could you please advise how to retrieve meta tags from page properties?

Thanks

 

 

Properties.PNG

Replies

 
Nicolai Høeg Pedersen
Reply

Hi Davor

If you simply add <meta name="description" content="" /> to your master or layout template, Dynamicweb will automatically fill the tag with the data for the page currently being viewed. Have a look in the Designs & Layout documentation how this works.

If a page does not have a description, Dynamicweb will not render the description tag.

Nicolai

 
Davor Zlotrg
Reply

Hi Nicolai,

If I add <meta name="description" content="" /> to my layout template I get Object reference not set to an instance of an object Exception.

Please see attached markup html and stack trace of exception.

Thanks.

Exception.PNG Markup.PNG
 
Davor Zlotrg
Reply

Hi Nicolai,

Also if I add attribute data-settings="disableparsing:true;" to my master head section the Exception is gone, but content attribute of description meta tag is still empty.

Thanks

description.PNG
 
Nicolai Høeg Pedersen
Reply

Hi Davor

I need the URL then...

 
Davor Zlotrg
Reply

Hi Nicolai,

Here is the URL:

http://195.249.142.64/

 

Thanks.

 
Nicolai Høeg Pedersen
Reply
This post has been marked as an answer

Hi Davor

Now it works. Just do what the manual says...

I removed this piece of code from your layout file:

<!--@SnippetStart(title)-->
    <title>@Dynamicweb.Frontend.PageView.Current().Meta.Title</title>
 <meta name="description" content="" />
<!--@SnippetEnd(title)-->

And this code from your master file:

@if(1 == 2)
    {
        <title></title>  
    }
    <!--@Snippet(title)-->

And then simply added a title and description tag to the master template.

BR Nicolai

Votes for this answer: 1
 
Davor Zlotrg
Reply

Hi Nicolai,

We needed that part for overriding the titles, but now we will do it another way.

Thank you for quick responses and fix.

Kind regards,

 
Nicolai Høeg Pedersen
Reply

Hi Davor

You can from every element (Page, news, products etc.) override the title on the UI.

If you need to do it from code, use Pageview.Current.Meta.Title:

http://developer.dynamicweb-cms.com/api8/#Dynamicweb~Dynamicweb.Frontend.Meta~Title.html

Nicolai

 

You must be logged in to post in the forum