Created
December 8, 2009 04:35
-
-
Save brettz9/251403 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
How about a templating system which looked like this? | |
Inspired by http://code.google.com/p/mjst/ and my earlier | |
http://gist.github.com/250870 | |
Could use PHPTAL-style attributes as well, but the use of "j" | |
attributes is for simple, not-so-ugly use and addresses the problem | |
that processing instructions cannot occur within tags/attributes | |
This solution does not necessitate any string or regular expression | |
processing whatsoever; all can be handled by the DOM | |
A pity there are no namespaces with processing instructions (and a pity | |
they cannot be used within tags)! | |
--> | |
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:j="http://brett-zamir.me/ns/js"><head><title></title></head> | |
<body> | |
<!-- If a static attribute name, simply use the attribute name in the "j" namespace, with ${} enclosing a dynamic variable --> | |
<p j:class="${dynamicValue}" j:id="${dynamicValue2}"></p> | |
<!-- Or use processing instructions --> | |
<?js echo('Evaluable processing instructions can create an <element/> or text nodes like this') ?> | |
<!-- Processing instructions might even create attribute nodes for the preceding element, if say as the first child of an element --> | |
<p><?jAtts echo({attName1:attValue1, attName2:attValue2}) ?></p> | |
<!-- If the attribute name itself must be dynamic, we could also resort to | |
reserved attribute names "dynNameN" where "N" is a positive integer --> | |
<p j:dynName1="${dynamicAttributeName}" j:dynValue1="${dynamicAttributeValue}"></p> | |
<!-- Or perhaps more simply with "dynAttrN" as our reserved attribute name and the name and value contained within, showing as... --> | |
<p j:dynAttr1="${dynamicAttributeName}{:}${dynamicAttributeValue}"></p> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment