Last active
December 21, 2015 05:09
-
-
Save drocco007/6254974 to your computer and use it in GitHub Desktop.
Kajiki basic/nested blocks
This file contains hidden or 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
parent = u""" | |
<!DOCTYPE html> | |
<html> | |
<body> | |
<div py:block="content">Eat your veggies!</div> | |
</body> | |
</html> | |
""" | |
child = u""" | |
<py:extends href="parent.html"> | |
<py:block name="content">Candy and TV! (parent said: ${parent_block()})</py:block> | |
</py:extends> | |
""" | |
import kajiki | |
from kajiki import MockLoader, XMLTemplate | |
loader = MockLoader({ | |
'parent.html': XMLTemplate(parent), | |
'child.html': XMLTemplate(child) | |
}) | |
tpl = loader.import_('child.html') | |
print tpl({}).render() |
This file contains hidden or 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
parent = u""" | |
<!DOCTYPE html> | |
<html> | |
<body> | |
<div py:block="content"> | |
Eat your veggies! | |
<span py:block="nest">nested block</span> | |
</div> | |
</body> | |
</html> | |
""" | |
child = u""" | |
<py:extends href="parent.html"> | |
<py:block name="content">Candy and TV! (parent said: ${parent_block()})</py:block> | |
</py:extends> | |
""" | |
nested = u""" | |
<py:extends href="child.html"> | |
<py:block name="nest">Nested content (nested parent said: ${parent_block()})</py:block> | |
</py:extends> | |
""" | |
import kajiki | |
from kajiki import MockLoader, XMLTemplate | |
loader = MockLoader({ | |
'parent.html': XMLTemplate(parent), | |
'child.html': XMLTemplate(child), | |
'nest.html': XMLTemplate(nested) | |
}) | |
tpl = loader.import_('nest.html') | |
print tpl({}).render() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment