TemplateTags
TemplateTags are tags which are used to retrieve data from a Dynamicweb solution and render it in a template, e.g. a product name, a paragraph text, or – well – everything else, really. Dynamicweb uses ASP.NET Razor to work with template tags, which means that you can use regular C# methods to work with e.g. string objects or datetime objects.
As the name implies, TemplateTags belong to a specific Template – you can read more about templates in Dynamicweb here – and for performance reasons not all tags are available in all template contexts. Alongside the tags you will find loops which enable iteration through collections of items like products, variants, or countries.
To know which tags and loops are available in a context you can:
- Browse this area of the Dynamicweb documentation portal – e.g. Content, Ecommerce, etc. – for information about the tags and loops available in a given template context
- Use the @TemplateTags() helper tag inside a template or loop context to generate a table with tags & loops available (Figure 1.1)
Get*-methods
To retrieved the value behind a particular TemplateTag you use a Get*-method with the name of the template tag as the parameter:
Method |
Returns |
Comments |
@GetValue(‘TagName’) |
An untyped object |
|
@GetString(‘TagName’) |
A string object |
|
@GetInteger(‘TagName’) |
An integer |
|
@GetBoolean(‘TagName’) |
A boolean |
|
@GetDouble(‘TagName’) |
A double |
|
@GetLong(‘TagName’) |
A long |
|
@GetDate(‘TagName’) |
A datetime object |
|
For example, in a shopping cart template you may want to retrieve the the Order ID of the order being created:
Please note that all Get-methods return safe values; GetInteger will always return a valid integer (0), even if the passed tag does not exist or does not contain an integer.
When you use Get*-methods to retrieve typed objects you have immediate access to all the lovely C#-methods for the type:
Loops
When you want to access values inside a loop – for instance products in a product list template – you use a foreach statement:
If you want to know what’s available inside a given loop, you can use the @TemplateTag() helper tag there as well: