Access Key Menu:

Skip to top of page.

The power of the RenderTemplate function

Umbraco is quite powerful, and has a robust set of exposed functions that make it even more powerful.  One such function is the umbraco.library RenderTemplate function.  This simple routine is the basis behind the content/template system that umbraco is built upon.

I am sure you are asking, how is this useful to me.  Well, there are many uses. 

Transfer that page

The first use is to seperate content.  For instance, you can set up your site to have all the generic site settings in one document type, etc.  But, you need to assign the domains to this page as well.  Instead of creating this as your default page, which you also have a standard page document type that would be better suited, you can just render that node as if you are on it.  Similar to doing a Server Transfer in many languages. 

Now, you could just redirect the page to the desired page, but, is that effective?  To accomplish a redirect, the server tells the browser that the page it is looking for has moved, and where it is now located.  The browser then has to request a second page.  Thus making the server answer another request, and wasting time and bandwidth (very little, but the point remains).  Remove that round-trip, and we have a quicker response.

View XSLT Code

Re-use that content

Another use of the RenderTemplate function is for content re-use.  How is this different?  I am referring to having content that may be rendered on multiple sites.  Currently, to accomplish this gracefully in Umbraco, you would need to write a UserControl to pull the data from a database and load it into the page template, formatted correctly for what you are wanting to show.

Instead of working outside of Umbraco with our data, why don't we just create a common content area, and re-use the content in our various sites?

By creating simple templates that only render the body of the content, we can dynamically include these pieces into our page.  Yes, you will have to use querystrings to pass the pageid of the content you want to display, otherwise, how will we know what to show.

Why would you want to do this?  The primary reason this may be desired is to wrap the website branding around the common content.  For example, rebranding a storefront.  You may want to offer the same stuff to every user, but with a different look and feel.

Thus, to accomplish this, on the actual page being called, we need our master template that contains all the branding, etc.  The child template then needs to call the RenderTemplate macro passing it the pageID and (optional) templateID of the content we want to encapsulate.  And there we have it, a dynamically called page rendered in a branded page interface.

Skip to top of page. Skip to top of page.