What’s in a name?

Of course, this quote is taken from the successful Romeo & Juliet by Baz Lurhmann.

How does it apply to ExpressionEngine? I've taken on a few EE projects lately where the naming conventions have been quite a bit off what I'm used to.

Other folks in the community have touched on naming conventions before (Joel Bradbury @ EEUK 2011 & Jamie Pittock @ EECI San Fran 2010) but I don't think those knowledge bombs have ever filtered out to a wider audience.

Naming Conventions

There are a few examples of conventions I've seen used in EE installs: open, loose, firm & strict. I'll say first up that I'm a big fan of a strict naming convention.

Open

I'm not going to lie, this was the first approach I ever used on the first blog I built with EE. It generally looks like this:

{body}
{description}
{content}
{content-image}
{images}

Now, depending on your site that may be fine if you only have 1 channel. If you add more channels and those channels need field for body copy or image it will get confusing.

Loose

We're getting a bit better here but still not ideal:

{body_blog}
{body-news}
{pagebody}

{blog_image}
{pageImage}
{news-image}

The names are a little more descriptive but there's still no real consistency.

Firm

Now this is much more like it:

{person_image}
{person_body}
{person_seo}

{news_image}
{news_body}
{news_seo}

To be honest, I'd take that approach, it's clear what each custom field refers to. However, taking it a step further makes much more sense for me.

Strict

As I said, this is how I prefer to do things in my EE builds:

{cf_event_body}
{cf_page_body}
{cf_audio_body}

{lv_our_history_en}
{gv_param_disable_default}

{cf_event_img}
{cf_page_img}
{cf_audio_img}

So what are we dealing with exactly? Well effectively our variable is broken now into 3 chunks (with a potential 4th if I was doing a multi-lingual site).

The prefix cf_ indicates the type of variable I'm defining, event_ defines the channel that my variable is being assigned to (note I generally use a 1:1 relationship between channels and field groups) body_ tells me the actual name of my field and finally, if I'm building a multi-lingual site en sets the language.

Prefixes

  • {cf_}   :   custom field
  • {sn_}   :   snippet
  • {gv_}   :   global variable
  • {sv_}   :   session variable
  • {cpf_}  :   custom profile field
  • {ccf_}  :   custom category field
  • {cmf_}  :   custom Matrix field
  • {cmc_}  :   custom Matrix column

The benefits of using this approach is when I revisit a site and dive into a template, I'm able to make much more sense of the logic quicker.

How do you configuration your variables within EE?