Site Layout Template Other languages:|. Problem How do I use a site-wide base template that displays across every page? (In other frameworks, this is called template inheritance.) Solution This can be done using the base attribute: render = web.template.render('templates/', base='layout') Now if you do something like render.foo() it will render the templates/foo.html template and then wrap it in the templates/layout.html template. The format for 'layout.html' should be a simple template that takes one variable. For example: $def with (content) Foo $:content If you don't want to use the base template for something, just create a second render object without the base attribute, like: render_plain = web.template.render('templates/') Tip: Page title is set in other template files which are then used by the layout (layout.html). Example: templates/index.html $var title: This is title. Hello, world templates/layout.html $def with (content) $content.title $:content Tip: Add css files in other template files. Example: templates/login.html $var cssfiles: static/login.css static/login2.css hello, world. Templates/layout.html $def with (content) $content.title $if content.cssfiles: $for f in content.cssfiles.split(): $:content The HTML output code looks like below. A huge collection of 3400+ free website templates, WP themes and more at the biggest community-driven free web design site.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
April 2018
Categories |