Three Best Practices for ExpressionEngine 2: save time and headaches
If you’ve done ExpressionEngine development for a while, you’ve probably developed some basic standards for how you manage your installs. If you haven’t, or you’re new to ExpressionEngine, Best Practices are an important part of effective development. Here’s a short list of Best Practices which will make your ExpressionEngine installs more reliable, flexible, and easier to troubleshoot.
1. Put common template elements in to global variables. For each site I develop, I use these global variables at minimum:
- {company-name}. I typically use this for the alt tag on the client’s logo, and for the footer copyright statement. If the company has a name and a slogan or tagline, consider splitting them up. This will give you flexibility in their use. For example, in some spots on the site you may need to display “Standard Widgets, LLC”, while in other spots: “Standard Widgets, LLC: Your Eternal Widget Source”.
- {google-analytics} Put the lines of JavaScript in to a global variable. This keeps your templates neat, and then you can call it with one line of code.
- {js-and-style} Putting all your calls to JavaScript and css files in one variable makes them quick to edit, and separate from templates.
- {twitter-url} Place common off-site links in to their own global variables. If your client changes their Twitter feed, or Facebook URL, you’ll be able to quickly swap it out without having to remember where it is in a template.
2. Use relative paths wherever possible. There are several advantage to this. First, code output by ExpressionEngine templates will be neater and easier to read, as will images and other files referenced in entries. Secondly, if you need to move the site from a temporary domain, like dev.mysite.com to a public domain, everything will continue to work correctly. And if your client simply changes their primary domain from standardwidgets.com to standardwidgets.biz, again, everything will continue to work correctly. Key places for this are channel preferences and file upload preferences.
- Channel preferences: Under path settings for each channel, enter a relative path. For example, instead of http://mysiterocks.com/articles/list/, just enter /articles/list/ For the home page, you need only enter /
- File upload preferences: Under Server path to upload directory, or course, you’ll need a server path like /www/mysitename/public_html/image-folder/. But for URL of upload directory, just use a path relative to the root of the site, like /image-folder/
3. Choose a web host and stick to it. Sometimes, of course, clients request or require that you use an unfamiliar web host. However, wherever you can, standardize on one web host. Whoever you choose, get to know how their server works, what they support, and you can rely on this for future ExpressionEngine installations. Using a variety of different servers will only increase your development time as you find that server A runs PHP 5.2 while server B has 5.16, server C does not allow shell access, and server D is behind some weird firewall which makes development very laborious. On a related note, some clients will insist on using their own chosen servers, whether or not those servers are equipped to handle ExpressionEngine and the various add-ons you use, and often without regard for giving you proper access to do your work.
Clients sometimes have an irrational love of a particular hosting company. Perhaps they’ve used company X for ten years, or they paid in advance and don’t want to part with $100 when you recommend company Y instead. Or they have a box on the floor under Lara’s desk that runs email, web, and the boss’ custom cupcake recipe application. Each case is different, however, where possible, use your skills of persuasion to steer clients towards a web host you can count on, one that won’t make development more difficult.





