When I was hired at LexisNexis back in 2003, it was to develop HTML templates, often to take to Usability testing. I’d been building actual web sites professionally for four years, so initially I felt this was “a step backwards”. Soon, however, I realized that template building is really more of an art, and indeed more elegant.
When you’re working on a website, you know what you’re building. When building a reusable template, there is a level of abstraction that must be accounted for. It’s a focus on the presentation layer for its own sake, rather than as the wrapping paper laid over the all-important data.
Over several years of template building, I’ve found there are several important notions that increase the efficiency in template creation as well as the overall quality of the deliverables.
Pick a Server-Side Scripting Language
PHP, JSP, ASP- I don’t care.
Identify variations in user or system state
A site of any complexity will have some level of variation in user or system states (authenticated vs unauthenticated, empty shopping cart vs non-empty). Identify these states up front, and determine what the implications are to the UI.
Create variables to represent each of these states. (loggedIn, cartEmpty). Use these variables to manipulate each individual variance across the site, in response to a query parameter being passed in. It is important to identify a default state.
By treating each variation itself, we are able to account for a greater number of combinations of states.
Be Lazy
Never code ANYTHING twice. Anytime something is on a design, ask if it will occur elsewhere. If so, make a generic version of it and include it. Coding anything more than once is not only inefficient, it risks introducing unwitting variation. If I pass off two pages to a development team and they each treat the same thing differently, which should be used? Leveraging the same code also helps to ensure the code is at an appropriate level of abstraction and can account for variation of data.
For me, the best template project involves the fewest number of discrete URLs.
Remember: this is a TEMPLATE
A template is commonly defined as a pattern. It should be simple to follow and easy to apply elsewhere. Remember madlibs? Enter in the appropriate type of word and it populates where it’s intended to be. That’s what templates should do. Define the rules around the content, and then just give it a slot to plug it in. If you have a column to hold images, build the framework around it to give the images the appropriate spacing you need; don’t expect the next person you hand the code to to apply your specific class names to elements. Dummy-proof it
Make your code apply to the whole, and then only code for exceptions as needed. If possible, push back on designs that necessitate “exceptions”.
Respect the Data (Unknown as it is)
Data coming from an external source is like a box of chocolates.. In the absence of specifics, the diligent developer must anticipate the possible areas of variation and recognize the boundary cases. A certain design may work wonderfully if there are three lines of text with a font size of 10px, but what happens when more (or less!) text is needed, or the visitor increases the font size? This is the difference between the designer and the template developer: one is in search of the ideal design, and the other anticipates the limits to which it may be pushed.
Know Where You Are
Relative paths can make or (literally!) break a template project. The use of absolute urls means you don’t need to worry what page is trying to access your assets from.
Assign Appropriate Class Names
This is related to the points above, but is still worth calling out on its own. Reuse code, recognize you’re creating a pattern, and be lazy. Use generic class names related to the overall semantics or layout (i.e. navbar), not the specific data you are trying to markup (search-results-sidebar). Naturally, exceptions can be coded with more specificity, because there must be some knowledge about the particular data for it to be recognized as an exception. But manually calling out the same type of layout of multiple pages is once again introducing the possibility of error: if we have 12 pages we’ve templated out and manually apply a style to 11 of them, is that an oversight or intentional? What do we do when we have to create a new page?
Plan for failure
Depending on the level of fidelity, a template project may or may not have javascript interaction in it. If so, it’s a best practice to check to ensure an element exists before acting on it. This should go without saying anytime, but it’s particularly important when the same footer (and JS script block — you DO put your JS at the bottom of the page, right?) is being pulled into different template pages. Always check to ensure an element isn’t null before attempting to manipulate it.
Explain, explain, explain
There is no shame to commenting code. Especially exceptions or default states. A name and initials is a nice touch as well, particularly when a project is in the early development stages. Many development teams will comment in the server-side scripting language so that it is not rendered in the outputted source code, and outsiders will not be able to see it. This is great; it is only the developers who need to be aware why things were handled as they were.
These are just a few of the tricks I’ve picked up over the past several years. It has occurred to me that template building is almost a different skill than straight-forward web development, and I wanted to capture some of the nuances. I imagine my friends and former coworkers could add to the list!








