O'Reilly logo

Umbraco User's Guide by Paul Sterling, Nik Wahlberg

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

FIGURE 4-14

image

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required