Custom Fields
ExpressionEngine has custom fields built right in to the system, no plugins needed. Also one can create as many custom field groups and fields as wanted for different areas of their site to customize the data entered. The data in the fields are also given their own field in the database making custom database queries simple and easy, and making searches by fieldname possible.
A custom field is an additional field to add information when writing a post, and to be able to use the field name as a tag name in the templates. The tag name is replaced by the content in the field.
Few realize how powerful this is. One can create new field groups and associate each to a different weblog, and we have the makings of a custom CMS that will outperform anything on the market. The combination of field data having their own rows in the database, unlimited field capability, use of the query module or php in the templates, and the use of conditionals allows for unlimited customizations of content and puts EE over the top as CMS
Two examples:
An events site:
description, start date, end date, address, map to location, hosted by, etc.
A Realtors Site:
Address, MLS, Price, Prop Size, and more.
Using custom fields and conditionals you can:
Type in a url and you have an rss feed added.
Type in a filename for a video and your video player is added.
Type in an address and a map is added with automated geocoding.
Type in a filename for a mp3 and a music player or podcast is added.
Enter the filename for a playlist and a video player with playlist is added.
Select dates.
Upload files to any directory and display them in any manner.
Browse and pick any file from any directory to include.
Include a photo gallery category or any image from a select list.
Use conditionals in the templates to include text or code in the page if the field has content.
Include scripts needed in the document head only if required.
Using conditionals, the code in the templates is only included if the condition is met, making for lightweight pages.
And much more…
This makes a site where an author simply enters the information in the fields and its formatted and shown as wanted.
In the control panel under Weblog Administration, Custom Fields this is the screen to add/edit custom fields.
Types of Fields:
Text Input: This is a single input line for text. It is the type of field you might use for a title, name, or other short information.
Textarea: This is a standard text entry box with multiple lines. This is what you would use for a main entry body.
Drop-down List: This creates a standard HTML drop-down list. You can define the contents of the list manually or pre-populate it from another custom field.
Date: field types are designed to display dates. This is perfect for events or other content where you want to include start/end dates. Next to the date field in your PUBLISH page you’ll see a calendar and two options for your date:
Localized: The date will be localized to the timezone of each user browsing your site.
Fixed: The date will NOT be localized and instead shown at the exact date/time you submit.
Here I added two date fields. Notice the calendars which add the date field automatically when clicking on a date, they are opened in the below screenshot.
Here are the fields opened to pick your dates.
Relationship:
This is a special and very powerful field type. It enables you to create relationships between two or more weblogs or with an image gallery so you can show content from one entry within another or select any image from your galleries to include..
Choosing Field Type “Relationship,” filling in the details, and adding the code for it created a drop down for each article where I can include any photo from the gallery in the article.
Here is the field created above opened to select a photo, and below is the resulting image, title, and caption, all from the gallery. I could make this any size and link to a popup or the gallery as well if wanted.:
Photo Gallery:
The gallery also has the custom fields option. There is provision for six extra custom fields usefull for any purpose wanted.
I hope this short article helps in some way in using your Expression Engine Content Management System.
Conditionals
In the next tutorial I will cover using “Conditionals” in conjunction with custom fields, a very powerful method of adding many functions to your templates while at the same time keeping your pages light weight. Using a template for many functions as the average CMS does as a matter of course, we run into situaltions where custom code is wanted on one page, but not on others.
The answer to this is custom fields used in conjunction with conditionals.
Conditionals are:
if x exists:
Do this (usually adding some code for a player, content of a field, or anything).
/if
This way if you have an mp3 file in a custom field a player can be included in your article, and if there is no mp3 file then no player will show nor will the code be on the page. This can be extended to maps, video, and many other options.
Example:
I have a cusom field for mp3’s and want to include a player and a download link.
Naming one field mp3, I would put this in the template where I want the player to appear:
{if mp3}
Code for player…where filename and path is reqd put the fieldname file=”{mp3}
Rest of code…
Another one for a download link: {mp3_dl}
{/if}
Save the entry and you have the player and the download link.
At the bottom is a player demonstrating this.
The conditionals makes for easy file inclusion and keeps the template lightweight by not writing in code when it isn’t needed. I have seen many large corporations with miles of code in every page that is only needed on a few because of using template system and not understanding the power of conditionals. One can have a number of different media players which will appear for the right file type this way, simply create a field for each media type and use conditionals. See The User Guide on conditionals for more.
If using the Enclosures plugin for podcasting, you can also have the RSS file done by adding rel=“enclosure” to the link.
In one demo we have, simply typing in the address into a field when writing an article geocodes it, adds the map coordinates to the database, to an xml file, and adds the map into the page with the link added automatically.
Get the Flash Player to see this player.