Class Tag
- Namespace
- Dynamicweb.Rendering
- Assembly
- Dynamicweb.Core.dll
Represents a template tag definition and its value.
[Serializable]
public class Tag
- Inheritance
-
Tag
- Inherited Members
Examples
using Dynamicweb.Rendering;
namespace Dynamicweb.Examples.Rendering
{
public class TagSample
{
public static void AddTags(Template template)
{
//Create a tag instance and add it to a template instance
var myTag = new Tag("greeting", "Hello");
template.Tags.Add(myTag);
//Create a second tag instance using its Name and Value properties and add it to a template instance
var myTag2 = new Tag();
myTag2.Name = "greeting2";
myTag2.Value = " World!";
template.Tags.Add(myTag2);
//Create a collection of tags and add it to a template instance
var myTags = new TagCollection();
for (int i = 1; i <= 5; i++)
{
myTags.Add(new Tag("Counter" + i.ToString(), i.ToString()));
}
template.Tags.Add(myTags);
//Examine all the tags in the template instance.
foreach (Tag tag in template.Tags)
{
if (tag.Name == "greeting")
{
//Found the tag in the collection named "greeting"
}
}
//Or look it up
if (template.Tags.ContainsTagName("greeting"))
{
//Found the tag in the collection named "greeting"
}
//And clear all tags from the template instances tags collection
template.Tags.Clear();
}
}
}
Remarks
A Tag is represented asd <!--@TagName--> in HTML templates. In XSLT templates the tag is a node in the form <TagName>Value</TagName>
Creating new tags to a template object should use SetTag(string, string)
Constructors
Tag()
Initializes a new instance of the Tag class.
public Tag()
Examples
See usage example in Tag
Tag(string, string)
Initializes a new instance of the Tag class and sets the value of a tag with the specified name.
public Tag(string tagName, string tagValue)
Parameters
Examples
See usage example in Tag
Tag(string, string, string, string)
Initializes a new instance of the Tag class and sets the value of a tag with the specified name and also renderes an attribute on the xml (if template is using a xslt template).
public Tag(string tagName, string tagValue, string xmlAttributeName, string xmlAttributeValue)
Parameters
tagName
stringName of the tag.
tagValue
stringThe tag value.
xmlAttributeName
stringName of the XML attribute.
xmlAttributeValue
stringThe XML attribute value.
Examples
See usage example in Tag
Properties
Name
Gets or sets the name.
public required string Name { get; set; }
Property Value
- string
The name.
Examples
See usage example in Tag
Value
Gets or sets the value.
public string Value { get; set; }
Property Value
- string
The value.
Examples
See usage example in Tag
XmlAttributeName
Gets or sets the name of the XML attribute. A tag is rendered as <DWPageID>54</DWPageID> in the XML. Using XmlAttributeName and XmlAttributeValue adds an attribute and the specified value to the tagname node.
public string? XmlAttributeName { get; set; }
Property Value
- string
The name of the XML attribute.
XmlAttributeValue
Gets or sets the XML attribute value. A tag is rendered as <DWPageID>54</DWPageID> in the XML. Using XmlAttributeName and XmlAttributeValue adds an attribute and the specified value to the tagname node.
public string? XmlAttributeValue { get; set; }
Property Value
- string
The XML attribute value.