| Paul's profilePaul Sterling's blogPhotosBlogLists | Help |
|
June 26 Multiple Instances of a Macro in a Single Umbraco TemplateI assume it's not an uncommon requirement to include multiple instances of a macro in a single template, but I hadn't encountered it until this week. In this case, a new site design dictated including multiple category listings on a single page. The problem was that our category listing controls were designed to render a single category listing determined by a query string parameter - though it doesn't look this way due to a Url Rewriting Rule. I borrowed a solution put forward by David Conlisk in this forum post termed "Resource Nodes." In essence what I've done is to create non-visible content nodes to contain the data used by the visible node. I simply added the properties I needed to the underlying Document Type. Again, I'm certain this is not an uncommon approach to Umbraco configuration and has the added benefit of providing a consistent model to our site editors. Following is a snippet from the Template underlying the visible Content node where the Macro parameter resourceNode is of the MediaPicker Data Type and the parameter ResourceNode is of the ContentPicker Data Type. When adding the Macros to the Template the creator simply selects the relevant Media node (for the Random Image Macro) and Content node (for the Category Listing Macro). <div class="prodImage"> <?UMBRACO_MACRO macroAlias="GetRandomImage" resourceNode="2211"> </?UMBRACO_MACRO> </div> <?UMBRACO_MACRO macroAlias="categoryList" ResourceNode="2545"> </?UMBRACO_MACRO> <div class="prodImage"> <?UMBRACO_MACRO macroAlias="GetRandomImage" resourceNode="1813"> </?UMBRACO_MACRO> </div> <?UMBRACO_MACRO macroAlias="categoryList" ResourceNode="2543"> </?UMBRACO_MACRO>
For a straightforward example of a Random Image Macro have a look at this forum post. Mine is implemented as a .NET User Control, but I think the XSLT solution is a bit more elegant. From here each Macro (.NET User Controls) retrieves the relevant configuration information from the specified ResourceNode and renders accordingly. Following is a snippet of the public property definition and usage from the User Control. ...(we create a public property to hold the NodeId)... private int resourceNode = -1; public int ResourceNode { get { return resourceNode; } set { resourceNode = value; } } ...(and then we get the value(s) from the related Node)... Node pageNode = new Node(resourceNode); categoryID = int.Parse(pageNode.GetProperty ("categoryID").Value.ToString()); In this manner I can add any number of instances of the same Macro to a Template and allow site editors to have control over the order and content of each Macro. As always, input on a better approach is welcome. June 05 CodeGarden08 Wrap UpWhew! The last 5 days have been extremely full and extraordinarily productive. My head is full of new ideas and items to consider. The energy and intensity of the Umbraco Core/MVP group is almost overwhelming and the passion for Umbraco and all the possibilities it affords are apparent in the community. The community response to the newly introduced commercial aspects of Umbraco were surprisingly well received. The new Umbraco Store is bound to see a stream of product listings in the next several months. Also, the general response to the current state of the Commerce for Umbraco project was quite positive and we added 3 contributors to the project this week. That's the best possible outcome I could've hoped for! Here are a few links to other CodeGarden08 sites: http://umbraco0008.web05.fab-it.dk/ http://flickr.com/photos/tags/codegarden08/ http://umbraco.org/documentation/books/codegarden-2008 It was an incredible event and I can't wait until next year! |
|
|