Ticket #1 (closed defect: fixed)
Site-wide master template covering multiple apps
| Reported by: | kevin | Owned by: | anonymous |
|---|---|---|---|
| Priority: | normal | Milestone: | 0.8 |
| Component: | TurboGears | Version: | |
| Severity: | normal | Keywords: | |
| Cc: |
Description
It needs to be possible to apply headers and footers to multiple applications that may be running behind a single TurboGears instance.
Change History
comment:2 Changed 6 years ago by kevin
- Status changed from new to assigned
I sent this snippet to the Kid mailing list this morning as an illustration that Kid appears to have a bug with py:extends going up multiple levels:
import kid
t1 = kid.load_template("""
<body xmlns:py="http://purl.org/kid/ns#" py:match="item.tag=='body'">
<p>t1</p>
<div py:replace="item[:]"/>
</body>
""", name="t1")
t2 = kid.load_template("""
<?python import t1 ?>
<body xmlns:py="http://purl.org/kid/ns#" py:extends="t1"
py:match="item.tag=='body'">
<p>t2</p>
<div py:replace="item[:]"/>
</body>
""", name="t2")
t3 = kid.load_template("""
<?python import t2 ?>
<body xmlns:py="http://purl.org/kid/ns#" py:extends="t2">
<p>t3</p>
</body>
""", name="t3")
print t3.serialize()
comment:3 Changed 6 years ago by anonymous
I just sent this to kid-template-discuss:
OK, well my py:extends "problem" appears to be a conscious choice in the code. Luckily, that means it's easy to "fix" if, indeed, the change in behavior makes sense.
Here's the lines I'm thinking along... you have a template for a page. That template extends an "application template" which matches on item.tag == "body" and adds its own header and footer. The "application template" extends a site template, which also matches on item.tag=="body" to add a site-wide header and footer.
Here's the code that handles matches:
for (match, call) in templates:
if match(item):
item = stream.expand() for ev, item in _coalesce(call(template, item, apply_func)):
yield (ev, item)
matched = 1 break
if matched: continue
So, it's very clearly stopping when it hits a match, which means that what I was looking to do doesn't work...
Here's what I'd want to happen...
- if you get a match, take the result of that reprocessing and apply
the remaining match templates against that.
It seems like this provides the behavior I want without getting into weird endless loops and other nonsense.
comment:4 Changed 6 years ago by kevin
I've made a patch for this yet, and sent it off to the kid list for a second opinion. I'll have to commit it before releasing though.
A version of this change is complete and in the repository. However, it appears that py:extend does not create a whole hierarchy for match rules: it only goes up a single level.