Navigatie

Contact

Send mail to the author(s) E-mail

View Richard Soeteman's profile on LinkedIn

RSS 2.0 | Atom 1.0 | CDF

Archief

Categorieën

Blogroll

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

Sign In

Zoeken

# Monday, 04 January 2010
Monday, 04 January 2010 21:37:53 (GMT Standard Time, UTC+00:00) ( Umbraco )

This Blog is not active anymore, further posts will be available on my company website. Read new posts here

This forum post  triggered me to share some code that I had. A while back I was building a site which  let the customers define their own custom overviews One requirement was that users could define the sort by property . To do this you can use the property picker but it wasn’t friendly enough for my case so I ended up building a custom macro parameter type.

To start you need to create a new class library and add references to the following assemblies:

  • Businesslogic
  • Cms
  • Interfaces
  • Umbraco
  • System.web

In the example below I’ve created a class that inherits from dropdownlist. This was the easiest way since I needed a dropdownlist and didn’t want to play with the control tree, Now more important is that this class inherits from the IMacroGuiRendering Interface.  This add two properties ShowCaption, to show the caption on the parameters tab and more important value which holds the selected value . 

   1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.Text;
   4:  using System.Web.UI.WebControls;
   5:  using umbraco.interfaces;
   6:   
   7:  namespace MacroRenderDemo
   8:  {
   9:      public class OrderBy : DropDownList, IMacroGuiRendering
  10:      {
  11:          protected override void OnLoad(EventArgs e)
  12:          {
  13:              base.OnLoad(e);
  14:              if (this.Items.Count == 0)
  15:              {
  16:                  this.Items.Add(new ListItem("Title", "nodeName"));
  17:                  this.Items.Add(new ListItem("Date", "createDate"));
  18:              }
  19:          }
  20:   
  21:          #region IMacroGuiRendering Members
  22:   
  23:          public bool ShowCaption
  24:          {
  25:              get { return true; }
  26:          }
  27:   
  28:          public string Value
  29:          {
  30:              get
  31:              {
  32:                  return this.SelectedValue;
  33:              }
  34:              set
  35:              {
  36:                  this.SelectedValue = value;
  37:              }
  38:          }
  39:   
  40:          #endregion
  41:      }
  42:  }

When you build the project and add the binary into the bin folder of your Umbraco site you still can’t select the new type from the parameter type list. First we need to register the class  in the database. Below you’ll see the database table that holds all the Macro property types.

dbrecords 

It is important that you add the Assemblyname  including the namespace to the macroPropertyTypeRenderAssembly column and add the name of your class to the  macroPropertyTypeRenderAssembly column .

Now we can use the parameter in our macro’s

parameters

and off course we can now use the new parameter in our template when we select the macro

InsertMacro

Another example how flexible Umbraco is. If a requirement isn’t available out of the box, usuallyall it takes is to implement an interface and write a few lines of code.

Monday, 04 January 2010 23:35:53 (GMT Standard Time, UTC+00:00)
I just love your blog posts, they are soooo usefull.

Thanks for sharing.
Mikael Mørup
Tuesday, 05 January 2010 20:15:39 (GMT Standard Time, UTC+00:00)
Awesome stuff Richard! Thanks for the code sample :)
Lee
Friday, 08 January 2010 21:17:40 (GMT Standard Time, UTC+00:00)
So I've tried to implement the code exactly how you have it. My issue is that the item and alias are not appearing when I try to add the macro to the table. Can't find any errors as far as I can tell.

I made 3 changes, the namespace, class name, and change from onLoad to onInit. Everything else looks identical to yours.

I've compiled it into a DLL and uploaded it. Other methods from the DLL are working correctly, but this one is just not working. I also removed it from the DLL and added it into app_code, but no luck there.

Please email if you have any ideas or ran into this issue....
Chad Rosenthal
Tuesday, 19 January 2010 14:37:12 (GMT Standard Time, UTC+00:00)
Richard,

I did something similar ages ago for umbraco v3 had a post about it on my old blog the source code is still up on codeplex see http://umbracoext.codeplex.com/SourceControl/changeset/view/45140 under macrorenderings basically you inherit from base class override some methods and you can have any datasource for your macro properties csv,xml, db have those already setup.

Regards

Ismail
Comments are closed.