/    Sign up×
Community /Pin to ProfileBookmark

MicroTemplating and XHTML compatibility

Hello, I have been using [URL=”http://ejohn.org/blog/javascript-micro-templating/”]John Resig’s micro-templating[/URL] script in the last weeks to manage js templates. Resig’s code is lightweight and simply requires the template to be inserted in a script container of type “text/html”. It turns out that this yields fairly numerous XHTML Transitional compliance errors if the template becomes complex (Among other things, invalid attributes, etc.).

I tried to wrap the code within CDATA tags, change the markers ( ie <,> to [[,]] ) to no avail except for one browser. Strangely enough, removing CDATA tags from the script template via Regex or substituting brackets works in FF 3+ but not in IE 7+, Chrome, Opera 9+, Safari 4, etc.

Is there a way to make Resig’s template implementation XHTML compliant or should I switch to a different approach? TIA.

to post a comment
JavaScript

8 Comments(s)

Copy linkTweet thisAlerts:
@CharlesJun 27.2009 — I don't know anything about that template thing but XHTML really isn't suitable for web pages. Your best bet is to stick with HTML. But you're not trying to create a JavaScript dependent web site, are you?
Copy linkTweet thisAlerts:
@mshelvauthorJun 27.2009 — Thanks for your reply. For your info, John Resig is the creator of jQuery and wrote a while ago about a lightweight js micro-template in his blog.

To respond to your question, I work with ASP.NET which defaults to XHTML 1.0 Transitional by default. Since I never had any major problems with this DocType, I tend to pretty much stick to it. What are the downside points if I switch to plain HTML?.
Copy linkTweet thisAlerts:
@CharlesJun 27.2009 — Down sides? None except that your page will work on slightly more browsers. If you really want your page to work, however, you need to use HTML 4.01 Strict. And not just the DOCTYPE, you need to follow the specification. http://www.w3.org/TR/html401/ .
Copy linkTweet thisAlerts:
@mshelvauthorJun 27.2009 — Thanks again. Out of curiosity, I changed the doctype to XHTML 4.01 Strict. Sure enough, this produced a rash of new validation errors I don't have time to correct. Though I know that strict is the standard to aim for, right noew I don't want to muddle with the mark-up.. Not enough time! :=)

If I stick to XHTML transitional, it seems that I will have to look for another template, Do you know of some lightweight templates that will validate?
Copy linkTweet thisAlerts:
@svidgenJun 27.2009 — ... but XHTML really isn't suitable for web pages.[/QUOTE]
huh?
Copy linkTweet thisAlerts:
@CharlesJun 28.2009 — Yes, it's true.
Copy linkTweet thisAlerts:
@svidgenJun 28.2009 — Yes, it's true.[/QUOTE]
... Go on.
Copy linkTweet thisAlerts:
@rnd_meJun 28.2009 — at work, i use xhtml 1.0trans for client's web sites exclusively.

i've never gotten a single complaint about the site not working in any browser...
×

Success!

Help @mshelv spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...