Completed Recipe 79, or thorough read-through Completed Recipe 80, to at least Step 3
The Theme wizard, which we used in Recipe 79 for a Simple List view, also offers a Grouped List view. We'll group items in a view by month.
The most convenient method for grouping with the Theme wizard is to simply store a new variable in the database, containing the group name. We'll use the Computed Field module to achieve this.
1. Complete Recipe 80, up to at least Step 3.
2. Install and enable the Computed Field module.
3. Click on Add field at admin/content/types/event/fields. Name the field Month, and select the Computed field. Click on the Create field button.
4. Enter the following into the Computed Code area:
$node_field['value'] = format_date($node->field_event_ date['value'], 'custom', "F");
You will probably recognize a portion of this code from Recipe 80. This time we're using the full name of the month (signalled by "F"), rather than the month abbreviation.
J This material is copyright and is licensed for the sole use by Richard Ostheimer on 26th June 2009 2205 hilda ave., , missoula, , 59801
5. By default, the Computed field has the Store using the database settings below option checked. Leave that checked in order to make the field available to Views.
6. Set the Length to 15 (although for now we just need a month name, we're leaving the option open to have the Month say something like November 2010).
8. View an event. Notice that the computed field does not display in a node by default. The field is available, though, and accessible to Views. If you wish to see the contents, one quick way is to click on the Dev render link, and examine the field_month array. At first, for existing content, the month value will be blank! You will need to save each existing node again to populate this field. You may do this manually (edit each content item and save), or you may install the regenerate module. Configure it to update events at admin/settings/regenerate.
9. Edit the events view. Change the View Type to a List View, and add the following three fields: Node: Title, Datestamp: Date (field_event_date), and Computed: Month fiield_month)
10. Go through the Theme Wizard again, this time, choosing Grouped List as the Theme Type, before clicking on Select Theme Type.
11. Select the node_data_field_month_field_month_value field on which to group, and click the Generate Theme button.
13. Remove the Month divs (the label, and the value) from the views-list-events.tpl.php file. There is no need to print them, since the month is already displaying for each group.
Was this article helpful?