Event List Macro

Event List Macro

Let's say you want a list of events on your home page. The following is an example about how this might be accomplished using Razor scripts.

The Structure:

  1. Construct a collection of events to iterate over
  2. Iterate over events and generate markup

My list macros usually have 2 distinct parts. When I break it down this way, i find it easier to write the macros quickly.

The first step is to actually generate the list I would like to render. This step is really very simple and you'll probably find that most of your time will be spent on validating your inputs.

In the second step, you simply iterate over the collection of data and generate HTML for it.

The Code:

You can see an example of what I did here.

Here are a couple of highlights for those who are new to razor:

Parameter.EventCategoryFolderId

That line of code references Macro parameters. In your developer->Macro section, select your macro and click the "Parameters" tab. These are parameters you can pass from your views to your razor script.

Model

As well as using Model to get a hold of nodes by id or name, Model can also be a reference to the "current node". For example, If we put the macro we are writing on the HomePage and call Model.Descendants(). We will be given a list of every node in the content tree nested under the HomePage. If we were to be on the About page when the macro was called, Model.Descendants() would provide a list of every node in the content tree nested under the About page.

Author

Mark Bowser

comments powered by Disqus
back to top