Developer forum

Forum » Templates » Global content as a static element on a template

Global content as a static element on a template

Jesper Brink
Reply
Hi

How do I define an element such as @DwFooter, that apperas with the same content on every template it is applied to?
I am already using the @DwFooter tag, but I need three similar tags in my template.


Replies

 
I. Sergey
Reply
Hello

You can use your own tag if you want. Write your tag in a template (e.g. in product list, your tag could look like  <!--@myTag-->). Create a custom module and write a code like the one below:


using Dynamicweb;

namespace CustomModules
{
    [Dynamicweb.Extensibility.Subscribe(Dynamicweb.Notifications.Standard.Page.OnOutput)]
    public class PageLoadedObserver1 : Dynamicweb.Extensibility.NotificationSubscriber
    {
        public override void OnNotify(string notification, object[] args)
        {
            if (args == null || args.Length == 0)
                return;

            object obj = args[0];
           
            if (!(obj is Dynamicweb.Templatev2.Template))
                return;

            Dynamicweb.Templatev2.Template template = (Dynamicweb.Templatev2.Template)obj;
            template.SetTag("myTag", "<div><b>It's my tag</b></div>");
            //Todo: insert code here
        }
    }
}


This code will replace all your tags with your own html code. You can also write your html code into a XML document and get it from there.

 

You must be logged in to post in the forum