Part of the EllisLab Network

Blog & News

Lisa Wess
Director of Community Services

Dissecting the Default Templates: Custom Weblog Fields

Last week I promised that we would soon be getting into custom fields.  Well, the time has come.

Remember, we’re currently in the middle of the weblog entries tag, in our index template of the default templates.  The next 3 lines of the template we know contain variables, and we know this because they are surrounded by curly brackets.  But what are these variables and where do they get their data?  It’s all in the magic of custom fields.  Shall we delve a bit further, then?

The next 3 lines in our template, then, are quite simple:

{summary}
{body}
{extended}

Now, if you search for these terms, you will find them mentioned in our documentation, but there is no dedicated page for them, as searched by “body”, “summary” or “extended”.  Why is that?  Our searches have always turned up a relevant docs page in the past!  The reason is simple:  while there is a set of custom fields created on installation, they are not required, or consistent amongst installations.  You can make your own custom fields, to hold whatever data you want, and in whatever format that you want. 

When you add or edit a custom weblog field you give it a Field Name - this Field Name is what becomes the variable above.  In essence, you are creating your own variables; but these are very powerful because they are attached to a weblog and let you define data for each entry, pull it into the public site, and act on it within your templates.

Why would you want to do this, though?  What could possibly be the allure of custom fields?

Well, let’s look at this.  Custom fields are essentially what make an ExpressionEngine weblog a “data container”.  By setting up custom fields you are specifying what the data is; that is, instead of being locked into the standard summary, body, and extended that make up a standard weblog, you could instead use this, for instance, as a links directory, where you could potentially set it up like this:

  • Title - remember - this is not a custom field, and is always required.  So you could use this as your link text
  • URL
  • Description
  • Site Owner
  • Site Screenshot

Now, this is all about dissecting the default templates, not about building a link directory site; however, it can often help bring on that light-bulb moment to see other scenarios in which a feature may be used.  Now that we’ve explored how differently custom fields can be used, let’s get back to our default template.

We saw the screen where we add and edit those custom fields; the most common question that we get regarding those is “why is it automatically adding paragraph tags?” - well, we can backtrack from the template to figure that out.  Now, we see {summary} in our template, so we know we are outputting the summary field, for a particular entry in a particular weblog.  But it’s adding all these paragraph tags; why is that?  Well, because custom fields have their own properties, configured per custom field, to allow for easy entering of data and letting ExpressionEngine do the heavy lifting of formatting the text.  In this case, {summary} is set to xHTML formatting.  We can change that by heading back to the Add/Edit screen and looking for the “Default Text Formatting for this Field” - if you do not want ExpressionEngine to do any styling, simply select “none”.

As you can see from the above, custom fields are very powerful:  they allow you to set up and control data how you want and each have their own properties so that you can decide on the appropriate formatting per field.  This concept is extremely powerful and allows you to dictate the handling and formatting of your content.

If you’d like to skip ahead, then next week we’ll get into displaying what categories an entry belongs to.  See you then!