Part of the EllisLab Network

Blog & News

Lisa Wess
Director of Community Services

Dissecting the Default Templates: Date Headings, Dates, and Titles

Last week we started to dig into the main content area of our default template.  We did this by opening up the weblog entries tag, and dissecting what the parameters did.

For our default template, the main content in the index page is delivered between the {exp:weblog:entries} opening tag and the {/exp:weblog:entries} closing tag.  Everything between is some form of variable (or, of course, HTML and CSS styling) which will be replaced during rendering so that your site visitors see actual content.

Now, don’t you think it’s time we take out the guts and examine them, so we know what they do and can accomplish the same on our own sites?

Here are the next 4 lines of our template:

<div class="entry">
{date_heading}
<h3 class="date">{entry_date format=' %l, %F %d, %Y '}</h3>
{/date_heading}

What we always do when dissecting a template is to figure out what each part of the template does.  So, now that we’ve come to a new variable, let’s search for date_heading in the documentation.  Our first result shows us exactly what this tag is about.  It will output the content inside the tag pair, in this case:

<h3 class="date">{entry_date format=' %l, %F %d, %Y '}</h3>

once for any group of entries that falls within its display parameter.  In the default index template, if you post 6 times in one day, the date will only show up once.  Now that we know that, we can also figure out that if we want the date to appear with every post, we will not need this {date_heading} tag pair at all.  Neat, eh?

Inside of the {date_heading} variable pair, we find the {entry_date} variable.  Our first search result tells us that this variable outputs the date we entered the post on (in the Date tab of the Publish form).  There are several date variables we find on that page, though our default template only uses {entry_date}.  However, remember: nothing in ExpressionEngine is assumed, and that includes the format for your dates.  As we can see, there is a link to date variable formatting which allows you to change the format of your date on the public page, using the format= parameter.  This can be very helpful if you want to show, say, only the Month, or the Month and the Year, or any variation thereof: the full list of arguments is always available in the documentation.

Now we get to the title.  The title of an entry is required - it is not a custom field, which we’ll dig into next week with the next part of the template.  The title is used in a multitude of places, including the edit page.  Even if you do not need to title your entries, fill this in with something recognizable for yourself so that you can find it again later.

However, our default template does, in fact, use the title:

<h2 class="title">{title}</h2>

This is a second level heading that makes the title really stand out, so that a viewer can quickly see what the entry is about.  The {title} itself is pulled from the Publish Page, where you entered the title; furthermore, the url_title, which is often used to link to single entry pages is derived, in a URL-safe format, from the title of the entry.

That is enough for now, next week’s article will dig into custom fields as our default index template calls {summary}, {body}, and {extended}: all of which are, in fact, custom fields.  So stay tuned!