Developer forum

Forum » Templates » ecommerce custom TITLE tags

ecommerce custom TITLE tags

Peter Bille Larsen
Reply

Is it possible to control the META TITLE tags in ecommerce, with ie:

shopname | productgroup | product
 
and then shown as:

<meta title = "minshop | solbriller | rayban ...

and then switch them around as you please ?

Replies

 
Vladimir
Reply
Hi Peter!

I think you can use a product template extender:
    public class ProductTemplateExtender1 : ProductTemplateExtender
    {

        public override void ExtendTemplate(Dynamicweb.Templatev2.Template template)
        {
            PageView.Current().Meta.Title = ...;
        }

    }

or use PageTitle notification subscriber and control title as you want...

Best regards,
Vladimir


 
Nicolai Høeg Pedersen
Reply
Or simply use the title field of the meta data on the product...
 
Peter Bille Larsen
Reply

Hi :-)

yes I know, but it should be dynamicly written, depending on ProductGroup, ProductName, ShopName.
We are using the SEO module, so can I still have a module which overwrites the meta data?
 
Nicolai Høeg Pedersen
Reply
Hi Peter

Yes - Vladimirs suggestion will still work.

 
Peter Bille Larsen
Reply

cool.
 
Davor Zlotrg
Reply

I know this is an old topic but I have an issue with rendering title tags the way I want.

I was hoping to be able to define title tag through snippets

In my master to have 

<!--@Snippet(titleTag)-->

And than in my template to have 

<!--@SnippetStart(title)-->
   <title> if something this title else this title </title>

<!--@SnippetEnd(title)-->

 

I get an error message after doing this. Is the notification subscriber the only way?

 
Nicolai Høeg Pedersen
Reply

Hi Davor

What error do you get?

What are you trying to achieve? In what template do you have the snippetstart and end?

Nicolai

 
Davor Zlotrg
Reply

Hi Nicolai,

I am trying to manually controll over rendering title tags (because I have a lot of dynamic custom content)

Here is the case scenario

I have a standard page that has let's say dealer template but the content depends on the query string parameters, something like this:

/delaer?dealerid=2        

/delaer?dealerid=3

/delaer?dealerid=4

It is the same template but I would like to have a different title tags based on information I have in the database for dealers with ids 2,3,4

 

So I have a master that all my pages are using

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" data-ng-app>
<head>

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE10,chrome=1" http-equiv="X-UA-Compatible" />
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">

    <!--@Snippet(titleTag)-->

</head>

....

 

And a dealer template 

<!--@MasterPageFile(master.cshtml)-->
<!--@Layout.Title(Dealers template)-->
<!--@Layout.Description(Use this layout for dealers pages)-->

<!--@SnippetStart(titleTag)-->

    @{
        string myTitle = "test";

        if(id == 2) { myTitle = "this comes from the database" };
    }
    <title>@myTitle</title>

<!--@SnippetEnd(titleTag)-->

<article id="frontpage-products">

...

 

So the idea is that the title tag is injected from the template to the masterpage.

I uploaded the error I am getting after doing this.

 

Dynamicweb version is 8.3.1.8.

 

Let me know.if you have any questions.

 

 

 

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

Ok...

In your master do this:

<!--@ If(1=2)-->

<title><!--@Title--></title>

<!--@ EndIf-->

<!--@Snippet(titleTag)-->

I know it is not pretty...

Nicolai

Votes for this answer: 1
 
Nicolai Høeg Pedersen
Reply

In your master you can also do like this:

<head data-settings="disableparsing:true">

 
Davor Zlotrg
Reply

Thank you very much for the quick response. It works :)))

 

One more question.

Is there any way I can check in the master if the snippet is defined in the template?

Something like this

@if(SnippetDefined('title'))

{

      <!--@Snippet(title)-->

}

else

{

         <title>take the default title</title>

}

 

That would allow me to have default title tags everywhere but I would have possibility to override it only for specific templates. I hope you understand what I am trying to achive here.

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

No, but you might be able to do

if(Dynamicweb.Frontend.PageView.Current.TemplatePage.Html.Contains("Snippet(title)"))

Votes for this answer: 1

 

You must be logged in to post in the forum