Lewis O'Neill wrote:
> The content template will be passed as an argument into the base
> template so at the top of the base template file use:
>
> $def with (content)
>
> where you want to insert the content into the template use:
>
> $:content
>
> so your template should look something like:
>
> $def with (content)
>
> <head>
> <title>TITLE</title>
> </head>
>
> <body>
> $:content
> </body>
>
>
> On May 23, 5:05 am, Bruce <[EMAIL PROTECTED]> wrote:
>> I'm new to web.py and trying to borrow from this recent example ..
>>
>> On May 8, 4:11 pm, Eric Talevich <[EMAIL PROTECTED]> wrote:
>>
>>> Not sure about Mako, but the built-in templating engine lets you pipe
>>> the output of one template rendering into another rendering call. Such
>>> as (for v0.23):
>>> some_calculation = 46 + 2
>>> print render.base("RedBaron's Homepage",
>>> render.layout(
>>> render.sidebar1(some_calculation),
>>> render.article("Why Python Rules", article_text)))
>>> This pipes the sidebar1.html and article.html templates into
>>> layout.html, which goes into base.html, and sends the resulting string
>>> to the browser. (In web.py version 0.3 replace the print statement
>>> with return.) ...
>> ... but the inner template (I have just 'base' and 'content') isn't
>> rendering. Is there something I need to do in the base template to
>> render that content?
Instead of using base templates I usually create a seperate template for
every page that has the <html> and everything and include common
elements from there.
To do this without having to pass the render object around everywhere I
implement a trick suggested by Ken in [1]:
render = web.template.render("templates/", cache=False)
web.template.Template.globals['render'] = render
Now, in every template I can do things like these:
<head>
$:render.head("Special page")
<meta name="robots" content="noindex, nofollow">
</head>
With a file template/head.html:
$def with (title)
$if title:
<title>$title -- UNISCA Contacts</title>
<style type="text/css">
@import url("/static/basic.css") projection, screen, tv;
</style>
Note how you can still easily add extra <meta> tags, for example.
I believe this is a good compromise between readability, flexibility and
consistency.
(To take it even further, I sometimes add this to my code file:
web.template.Template.globals['py'] = web.storify(__builtins__)
Now I can access all python builtins in my templates, like:
$if py.isinstance(value, py.int):
$value
$else:
<pre>$value</pre>
But I prefer not admit this to too many people ;P)
Greetz,
b^4
[1]
http://groups.google.com/group/webpy/browse_thread/thread/b7cdc00f7e970396/cb25c0728c3488b3#cb25c0728c3488b3
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web.py" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/webpy?hl=en
-~----------~----~----~----~------~----~------~--~---