USING ALTTEMPLATE
Often times the same content may need to take on different shapes to serve a different purpose. One very common, and timely, example of this is switching the layout of your content for a mobile device. Traditionally, the developer must create a different document type with the same properties, create a duplicate page for the same content, and apply the alternate template to serve up the alternate view.
There are cases when you need to present certain content in multiple formats. In this section, you'll see how data that is presented in one way can be repurposed by using something in Umbraco called AltTemplate.
Umbraco enables you to create and assign multiple templates to a particular document type. Make sure that you're targeting at least one of the same document type properties across the multiple templates; otherwise none of your content will be displayed. You can allow multiple templates for one document type by selecting them in the Info tab of a selected document type, as show in Figure 4-14.
Now that you've assigned all the templates for the document type—your content container—you can dynamically load this template by appending the following to the current URL:
?altTemplate=template2
This causes the current page to reload with the alternate template applied. The beauty of this is that the content author didn't have to create two separate pages ...
Get Umbraco User's Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.