0
votes

I have an Umbraco site

...with various document types, e.g.:

  • page
  • publication
  • event
  • news

...and various templates, e.g.:

  • home
  • content
  • content with listing
  • content with embedded media (e.g. a youtube video)

Within a template I have some optional macros / widgets. For example, sometimes a page with the "content" template will display a "search site" widget, and sometimes it wont. Whether or not a particular widget is displayed on a particular page will be controlled by the CMS admin (who isn't a developer).

Adding a template for each combination of widgets isn't an option: if the "content" template has optional widgets W1, W2, W3 then I'll end up needing to create a template for each member of the powerset of those widgets - i.e. I'll have to multiply the number of templates I have by 8 (2^n) for just 3 optional widgets (there'll be more than 3 optional widgets for the real site).

So I'd like to toggle the display of widgets on and off, based on a parameter set by the user in the Umbraco backend somewhere. The actual toggling on and off is very easy - I'll just add an "if (widgetX_is_turned_on)" statement in my user control.

But, as far as I can tell, I can only add properties to document types, not to templates. I'd prefer not to add a property for toggling every widget into my root document type, because many of those toggles / properties will end up doing nothing if the template associated with a document doesn't allow a certain widget. For example if I create a "page" document called "Example Page" with a "content" document type, then the "display search site widget" toggle / property will do nothing if the "content" template doesn't actually allow the display of the "search site" widget.

Is there a neat and tidy way to parameterize a template so that I can switch macros / widgets on and off for individual documents?

1

1 Answers

1
votes

Basically what you do is create seperate document types for your widgets and then link them to your content. You could even inherit widgets from parent documents if no widget has been chosen for the current page.

A good explanation of this concept can be found in this blog post: http://blog.hendyracher.co.uk/sidebar-widgets-with-umbraco-v4/