This is the celebrated journal of Mr. Simon Collison A.K.A Colly

Thursday’s Expression Engine snippet

10th November 2006

After a quick check of my days-of-the-week pants, I can tell it’s Thursday, so time for today’s episode. We’re going to be building a simple what’s on guide, so hang on to your hats.

1. Setup your weblog

Start by creating a new weblog called events, then create a new custom field group and associate it with the new weblog. Now add some fields to the new custom field group. For this example we just need a couple of fields for details of the event and the venue. So setup event_detail and event_venue and we’ll use the title field for the name of the event. Small point, but I always add an explanatory prefix to my custom fields. Now stick in some dummy data for testing, making sure your events have dates in the future. If you’re feeling bold, create a venue weblog, and relate it to the event_venue field.

2. Make a template

Now make yourself a new template. I always find it useful to have a neat and tidy template ready-rolled for these kind of situations with just a very basic layout, ready to drop EE tags into. And it’s time for a weblog tag.

{exp:weblog:entries
weblog=“events”  orderby=“date”
limit=“10” show_future_entries=“yes”}

We’re pulling out the latest ten entries from the events weblog, and we’re showing future entries too, since our events are upcoming. Now pull out the custom fields using something like this: -

<h4>{title}</h4>
<p>{entry_date format=”%Y %m %d”}</p>
<p>{event_detail}</p>
<p>{event_venue}</p>

And close up your weblog tag for good measure.

3. Add the dynamic stuff

Now for making it all dynamic. First, check out this page in the docs. We need to tell the weblog tag that we’re going to be using dynamic parameters, and which parameters are going to be dynamic. Add the following into your opening weblog tag: -

dynamic_parameters=“month”

For this example, we’re just going to be setting the month dynamically, but you can add more parameters too.

Finally, drop the following chunk of code in above your weblog tag.

<form method=“post” value=“index.php”>
<select name=“month”>
<option value=”“>Month:</option>
<option value=“01”>Jan</option>
<option value=“02”>Feb</option>
<option value=“03”>Mar</option>
<option value=“04”>Apr</option>
<option value=“05”>May</option>
<option value=“06”>Jun</option>
<option value=“07”>Jul</option>
<option value=“08”>Aug</option>
<option value=“09”>Sep</option>
<option value=“10”>Oct</option>
<option value=“11”>Now</option>
<option value=“12”>Dec</option>
</select>
<input type=“submit” value=“Go!” />

And we’re about done for this example. Hopefully this gives you a quick sketch of both how simple it is to use Expression Engine for all those non-blog based sites, and hints at how a dynamic listing can be created.

Responses

# tester responded on 10th November 2006 with...

hello - just testing your lovely comments box!

# Brendan responded on 10th November 2006 with...

Can we see an example?

# Simon Collison responded on 13th November 2006 with...

I wish we hadn’t lost that sortable dynamic thingy I did with this technique as a test earlier this year. D’oh. Did you ever find it, Simon?

Responses are now disabled Your ability to respond is disabled automatically some 30 days after articles are published, or manually much sooner if spamming guttersnipes target a particular article.

Prev 662 Next

Superfluous Aside

Archived in ExpressionEngine, Design & Web

There are 4 responses

External References

Copyright © Mr. Simon Collison 2003-2017. Protected and licensed under a Creative Commons License. Grab the RSS feed

Engineered in Nottingham, scaffolded by ExpressionEngine, steam-pumped by United & kept alive with tea and hugs.