I'm in the middle of a mammoth site build using ExpressionEngine, the same CMS I use to power TNF. In fact, part of the reason I decided to rebuild my personal site on EE was to prepare for this project. And holy shnikeys, I'm glad that I did.
Over the next few weeks, I'll be posting about some of the best tricks I've learned during this particular build. It's a nice hefty list and growing daily.
Let's start with the simplest:
Invoking ExpressionEngine's input class in your templates.
Sound tough? It's not.
EE uses a class called $IN to fetch any incoming data from a user of your site. This includes page requests – in the form of a URL – but can also include data submitted to the $_POST variable, and even client-side info like browser type. The ExpressionEngine documentation mentions it (see link above), but it only gets a detailed analysis in the context of module and plugin building. That's too bad, because its utility can trickle down to us lowly template builders, too.
The trick that's been most useful to me was ripped straight from this comment on the documentation. The code goes like this:
- <?php
- global $IN;
- $seg1 = $IN->fetch_uri_segment('1');
- if ($seg2 != '' && $seg1 == 'foo') {
- ?>
- ...do stuff...
- <?php } ?>
All you're doing is invoking the $IN class and then getting at the data using the class' methods. Set your template to process php on input, and you're good to go.
If you've used ExpressionEngine before, you may be thinking "Uhh...yeah? Big woop. I can already do that with EE's built in URL segment variables." But there's a big difference: you can't evaluate EE's proprietary global variables the way you can evaluate a standard php variable. Por ejemplo, you can't do anything like this:
- <?php
- if (is_numeric($seg3)) {
- ?>
- ...do stuff...
- <?php } ?>
This trick can be especially useful if, say, you want to show a particular chunk of results if the URL was part of a homegrown date-based archive scheme you'd concocted. Sure, EE has a date-based archived system, but in some scenarios, it can't deliver what you need. And then the $IN class becomes your best friend.
There are a bunch of other classes that could be used in a similar fashion – including the $OUT class (for which no documentation exists) and the likely-to-be-more-useful $TMPL (or template) and $DB (or database) classes.
So go – muck up those templates. And let me know how you get on.






Whaddya think?