// you’re reading...

CMS

Render Tags – An Overview


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
!!%>

Manipulating the returned content

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)
!!%>

Control output based on render tag queries

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)
!!%>

<If> and <else> render tag queries

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>

In the Loop

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>

Reading structure elements

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>

Undocumented and documented render tags

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.

Disclaimer

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.

Links

Do you know any render tag tricks? Let us know!

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;.

Share and Enjoy:
  • Print
  • email
  • Twitter
  • Digg
  • Reddit
  • StumbleUpon
  • Google Bookmarks
  • del.icio.us
  • MisterWong
  • Facebook
  • LinkedIn

No related posts.

About the author:

Markus Giesen Markus Giesen is a Solutions Architect and RedDot CMS Consultant, formerly based in Germany. Travelling around the world to find and offer solutions for a better world (in a very web based meaning). He just found a way to do this as part of a Melbourne based online consultant house. On this blog Markus shares his personal (not his employers) thoughts and opinions on CMS and web development. In his spare time you will find him reading, snowboarding or travelling. Also, you should follow him on Twitter!

Discussion

15 comments for “Render Tags – An Overview”

  1. 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.

    Posted by Tiffany France | September 29, 2009, 5:06 pm
  2. [...] 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 [...]

    Posted by Execute code only on the RedDot CMS server by using render tags | RedDot CMS developer & TYPO3 freelancer blog - Markus Giesen | October 5, 2009, 6:31 am
  3. 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.

    Posted by Joel | November 17, 2009, 9:52 pm
  4. I am just beginning with Render Tags and find this very helpful, thank you.

    Posted by Joseph Belgium | November 20, 2009, 2:49 pm
  5. 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 :o )

    Posted by Simon Lewis | February 4, 2010, 3:00 pm
  6. @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.

    Posted by Markus Giesen | February 5, 2010, 2:58 am
  7. Ok MarKus, I’ll bear that in mind. Many thanks.

    Posted by Simon Lewis | February 5, 2010, 11:54 am
  8. Hi Markus,

    nice overview!

    Another undocumented render tag:

    <%!!context:CurrentPage.Template.Id !!%>

    The GUID from the Template

    Posted by Stefan Renneke | March 22, 2010, 10:09 am
  9. 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 )

    Posted by Markus Giesen | March 24, 2010, 2:12 am
  10. 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

    Posted by Andry Poernomo | November 14, 2011, 7:52 am
  11. 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

    Posted by Fulvio | January 11, 2012, 7:36 am
  12. 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

    Posted by Sree | July 29, 2012, 11:09 am
  13. This list is very helpful for all template developers. Great post !!!

    Posted by Gerlando Caldara | August 6, 2012, 10:56 am
  14. Hey Markus, i have something new for you. :)

    Try

    and

    Posted by Stefan Renneke | April 25, 2013, 4:35 pm
  15. Context:CurrentPage.Template.Description

    Context:CurrentPage.Template.PageDefinitions

    Posted by Stefan Renneke | April 25, 2013, 4:37 pm

Post a comment



Stay up to date! - Get notified about followup comments

If you don't feel the urge to comment but wish to stay in the loop:
Just enter your email and subscribe to new comments.

Subscribe without commenting

Recent Tweets

  • RT @AirKraft: Transport Canada breakout: they manage 80K pages and 300K assets with WSM(RedDot). Wow! #OTCW 2010-11-11
  • The RedDot usergroup session 'Future of WCM' is in National Harbor 7, now. See you there! #otcw 2010-11-11
  • RT @yttergren: @AirKraft: Calling all WSM(RedDot) devs: share your solutions on http://bit.ly/bgPIof EVERY solution can win an iPad #OTCW 2010-11-10
  • Come to the Solution Exchange session. Enhance your (#reddot) CMS project! Chesapeake 12, 3:20pm #otcw Looking forward to see you there! 2010-11-10
  • More updates...