Render tags can be used in many different ways. By using them one not only is able to read content from several places in the project you also can change and manipulate page rendering and use the render tag technology for your control structures.
The following list gives a overview and is meant to be an introduction into the functionality and use cases for render tags.
The most common use of render tags is probably the output of content:
<%!! Context:CurrentPage.Elements.GetElement(std_elem).Value !!%>
Only returning content might often be not of interest. This can be done by a reference or just the element placeholder itself. Hence here are a couple of ways to manipulate the render tag content output.
PadRight()
Return the content of an element with a maximum length of 15 characters
<%!! Context:CurrentPage.Elements.GetElement(std_elem).Value.PadRight(Int:15) !!%>
Substring()
Return the first 10 characters of a content element
<%!! Context:CurrentPage.Elements.GetElement(std_elem).Value.Substring(Int:0, Int:10) !!%>
Trim()
Return content and remove white space from beginning and end of string
<%!! Context:CurrentPage.Elements.GetElement(std_elem).Value.Trim() !!%>
Replace()
Return element content but replace parts of the string. In this example I replace “RedDot” with “OpenText”
<%!! Context:CurrentPage.Elements.GetElement(std_elem).Value.Replace(RedDot,OpenText) !!%>
ToUpper()
Return the output in UPPERCASE
<%!! Context:CurrentPage.Elements.GetElement(std_elem).Value.ToUpper() !!%>
ToLower()
Return the value of the string in lowercase
<%!! Context:CurrentPage.Elements.GetElement(std_elem).Value.ToLower() !!%>
ToString()
Change the output type to type “String()”
<%!! Context:CurrentPage.Elements.GetElement(std_elem).Value.ToString() !!%>
Length
Return the character length of returned value
<%!! Context:CurrentPage.Elements.GetElement(std_elem).Value.Length !!%>
HtmlEncode()
Return HTML encoded value of the element
<%!! Escape:HtmlEncode(Context:CurrentPage.Elements.GetElement(std_elem).Value) !!%>
HtmlDecode()
Return HTML decoded value of the element
<%!! Escape:HtmlDecode(Context:CurrentPage.Elements.GetElement(std_elem).Value) !!%>
Render tags are not only used to return element content.
It also can be used to check the value of an element and create several types of queries.
Equals()
Checks if two Strings are equal or not, return value is type of Boolean
<%!! Context:CurrentPage.Elements.GetElement(std_elem).Value.Equals(STR) !!%>
StartsWith()
Checks if the returned content starts with the given value (i.e. character) Return value is of type Boolean
<%!! Context:CurrentPage.Elements.GetElement(std_elem).Value.StartsWith(STR) !!%>
EndsWith()
Checks if the returned content ends with the given value (i.e. character) Return value is of type Boolean
<%!! Context:CurrentPage.Elements.GetElement(std_elem).Value.EndsWith(STR) !!%>
These return values can be used as well as queries which are known from other programming languages.
Another way of controlling output for example are <if>- and <if>-<else>-queries
<IF>
<reddot:cms> <if> <query valuea="Context:CurrentPage.Elements.GetElement(std_elem).Value" operator="==" valueb="String:test"> <htmltext> Value is "test" </htmltext> </query> </if> </reddot:cms>
This IF-query can be enhanced by the ELSE-query which comes in handy when you need an SSL-Switch or you want to Skip levels in your navigation
<IF>-<ELSE>
<reddot:cms> <if> <query valuea=" Context:CurrentPage.Elements.GetElement(std_elem).Value" operator="==" valueb="String:test"> <htmltext> Value is "test" </htmltext> </query> <query type="else"> <htmltext> Value is certainly NOT "test" </htmltext> </query> </if> </reddot:cms>
Beside these two options render tags offer other solutions. One of those is the possibility to use render tags for the output of elements within or outside of structure elements. For example you can use those outside of navigation manager templates to return your project structure
foreach
<reddot:cms> <foreach itemname="item" object="Context:CurrentPage.SubIndexes" countername="counter"> <htmltext> <%!! Store:counter !!%>. <%!! Store:item.Headline !!%><br /> </htmltext> </foreach> </reddot:cms>
Not only can this be used to return your navigation structure at any point of the project – you also can use it to return the structure elements (lists, anchors, container) of any page. Although – in Version 7.5.x – not in the right sort order.
foreach
<reddot:cms> <foreach itemname="item" object="Context:CurrentPage.Elements.GetElement(lst_elem).Value" countername="counter"> <htmltext> <%!! Store:counter !!%>. <%!! Store:item.Headline !!%><br /> </htmltext> </foreach> </reddot:cms>
Beside those and the already described functions in the documentation there are a couple of others which aren’t documented (yet?). For example it is possible to return the name of a content class by using this
Template
Reading a content-class
<%!! Context:CurrentPage.Template.Name !!%>
Render tags were quite new and a lot Open Text / RedDot CMS developers are used to ASP with VB.Net but these new tags are worth to have a look at because some of them can reach into parts of the project were you are stuck with your ASP code or you would have to use RQLs which can be slow down the editing process.
Be aware of undocumented render tags, they might change with the next version of RedDot (oh, wait, there might be no next major version after version 10..) ok, they might change with the next hotfix and then you have to walk through your system and find the little buggers. We also don’t give any warranty for the code shown here, use it at your own risk.
Show your render tags below in the comments field, but don’t forget to escape your HTML, which means that the code must be escaped by using HTML-Entities. For example one should write < as & lt;
and > as & gt;
.
No related posts.
This is helpful. I’d also use render tags to pull the parent page’s element value:
< %!! Context:CurrentPage.MainLink.OwnerPage.Elements.GetElement(std_elem).GetHtml() !!%>
I use this constantly for non-structural elements. I’d like to find a way to pull in a parent page’s dynamic anchor links, though render tags don’t seem to work for dynamic elements.
[...] 2009-10-05: After mono and some others asked for it I found some time and now you can find here a good overview for Render Tags (5 votes, average: 5 out of 5) Loading [...]
Just a quick comment. Tiffany your code actually pulls the information from the Main Link, which may be different from the parent if the page is linked in several places (main link is actually the original link to the page when it is created).
will pull from the parent page.
I am just beginning with Render Tags and find this very helpful, thank you.
Hi MarKus,
Thank you for this page… very useful. What was particularly useful was the one about replacing RedDot with OpenText. At first I thought it was a mistake because there were no string delimiters around these two words. So I tried it, and discovered that because it’s correct and works, I can use this function for the age-old problem of how to escape double quotes from text placeholders in RedDot when assigning the placeholder contents to an ASP variable. Fantastic! That’s just reduced (in some places) dozens of lines of code into just one
)
@Joseph, you’re welcome.
@Simon – if you try and use Render Tags to get content out of text elements you have to be careful.
Text elements need to be ASCII or you have to make sure that you don’t ever will have links or images inside the text element because they will break the Render Tag.
Would be nice if Open Text would fix that one day (hint).
To ensure this never happens you would have to disallow links and images in the text editor settings.
Ok MarKus, I’ll bear that in mind. Many thanks.
Hi Markus,
nice overview!
Another undocumented render tag:
<%!!context:CurrentPage.Template.Id !!%>
The GUID from the Template
Hey Stefan, great render tag! That can come in handy when using Plugins which create new pages based on Template guids.
Do you know if this works with references to different pages, for example like this:
<%!! Context:Indexes.GetIndexByPageId(Guid: 2FCD2CF681F94CC68D5AECB68C).Page.Template.Id !!%>
Would be nice to know!
I will test this!
(I copied this and modified it from here: http://www.reddotcmsblog.com/using-render-tags-to-translate-a-site-easily )
Hi Markus,
This is awesome!! Just something I need to refer too.
Do you however know to read query string for the render tag quiries? I need to do an A-Z page list and also create a list of pages based on a page category.
Cheers mate!
Andry
Hi,
Just wondering whether it’s possible using RQL to determine inside a Content Class what publishing targets are available?
I would need to do something like:
Dim PublishedUrl
If (UAT_Target)
PublishedUrl =
Else If
PublishedUrl =
End If
Hi Stefan,
I am new to RedDot CMS. I have one folder with contents and subfolders, again each subfolder will contains contents and subfolders. Is there any way to generate RSS feed of all pages ?
appreciate your help…thanks in advance…
Thanks,
Sree
This list is very helpful for all template developers. Great post !!!
Hey Markus, i have something new for you.
Try
and
Context:CurrentPage.Template.Description
Context:CurrentPage.Template.PageDefinitions