Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • George 28 posts 71 karma points
    Mar 23, 2011 @ 04:01
    George
    0

    How do I parameterize an Umbraco template?

    I have an Umbraco 4.6.1 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?

    (Note: this is a crosspost from http://stackoverflow.com/q/5400302/633626, I hope that's not considered spam. If I get a solution on either page I'll update the other so that the right answer is coming up in Google, so feel free to answer in either place.)

  • Richard Soeteman 4035 posts 12842 karma points MVP
    Mar 23, 2011 @ 08:38
    Richard Soeteman
    1

    Hi,

    I would create macro's for the optional widgets and use a document property based on the MAcro container datatype to add (or not) the widgets on your template. This is the easiest way I guess.

    Small tip I think you got your answers faster using this forum instead of stackoverflow ;-)

    Cheers,

    Richard

  • Sebastiaan Janssen 5044 posts 15475 karma points MVP admin hq
    Mar 23, 2011 @ 08:40
    Sebastiaan Janssen
    1

    @Richard In this case I saw it earlier on SO ;-) But you get more and better answers here on the forum.

    @George: 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/

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Mar 23, 2011 @ 08:45
    Jan Skovgaard
    0

    You rock guys! And the atmosphere in here is way better than on SO :-)

    /Jan

Please Sign in or register to post replies

Write your reply to:

Draft