|
You are here: Home / Documentation / XT Tips & Caveats |
XT Tips & CaveatsXT is a full-blown template language, and as such, learning XT is like learning a new language. With any new language there are quirks and things that seem odd when coming from another language, which might have a different way of doing things. The following is an in-depth overview of the most common quirks people encounter when first working with XT, including examples and solutions to problems that they can create for template designers. The Basics: HTML Versus XMLThe first thing you need to know about the XT template language is that templates are not ordinary HTML or text files. They are XML documents, and the XT template engine requires that they follow the same rules as any syntactially valid XML document. For those of you familiar with XHTML (the future of HTML), you will already have some idea what this means, although there are many additional bits of information in this article that will still be relevant to you. For those of you with no idea what I'm talking about, XHTML is HTML with a few new rules, so that it qualifies as a valid XML document. It's HTML written in XML. But it's pretty easy to get used to. XT doesn't even require that you obey most of the new XHTML rules, just the syntax-oriented ones. However, we encourage you to follow the whole spec, since there are many benefits (that are outside of the scope of this article) for doing so. Here are the relevant changes from HTML to XHTML: 1. Tags that don't have matching closing tags need to be "self-closing". For example:<img src="lux.jpg"> becomes: <img src="lux.jpg" /> The difference is a space and then a forward-slash before the closing angle bracket. The space is optional in XML, but is a little trick that fools older browsers into rendering XHTML as if it was ordinary HTML. The tags that this applies to in the HTML spec include:
The tags <option>, <li>, and <p>, that are commonly left open are actually supposed to have closing tags (ie. <li>List Item</li>). Note for you XHTML/standards gurus: I didn't mention the alt attribute because it's not a syntax change, it's an accessibility change. Since this is not a lesson in XHTML, but a quick "HTML versus XML" comparison, I'm going to avoid those. But I do recognize their importance. 2. Tags must close in reverse orderIf you've opened an <em> tag after a <strong> tag, then technically the <em> tag is considered to be inside of the <strong> tag. As a result, the <em> tag should be closed before the <strong> tag is, so that the integrity of the document structure is maintained. This makes it possible for the document parser to be certain of which </em> belongs to which <em> at all times. XML, and consequently XT, requires this unambiguity. 3. Leave a space between empty tagsYou might notice that your named anchor tags aren't working out for you, and wonder why. Well, because XT can't tell the difference between: <a name="top"></a> And: <a name="top" /> This is another less pleasant quirk of the xml_parse_into_struct() function. How we solve this is by adding a single space between the empty tags, which is enough to tell XT that our tags are of the former kind, not the latter. For example: <a name="top"> </a> 4. Tags should, but don't have to be, lowercaseThis isn't necessary for XT, but it is a syntactic part of the XHTML specification, and it's good advice to help save your shift-finger. Stop writing <HEAD> and start writing <head> instead. Much nicer. Takes some getting used to at first. Well worth the effort, believe me. For more info about XHTML, see: Page 1: The Basics: HTML Versus XML |
|
Copyright © 2008, SIMIAN systems Inc. All rights reserved. Privacy policy Some of the icons on this site were created by the Gnome Project. |