-
Notifications
You must be signed in to change notification settings - Fork 21
Using a common header file, how do I have unique titles per page?
colevscode edited this page Dec 7, 2014
·
1 revision
Right now if you want to have a custom title on each page, the simplest solution is just to include the <HEAD>
block with a unique <TITLE>
tag at the top of each page. If you're including a common headers.html partial, there's no out-of-the-box support for having a unique title for each page. You can do it, but you'll need to add custom tags.
For example you could do something like this:
in tags/tags.py
@lang.add_tag
def include_with_title(path, title, context={}):
'''
Renders the content of a file, adding a title variable to the context.
'''
context.update(title=title)
return include(path, context)
@lang.add_tag
def title(context={}):
'''
Renders the title variable from the current context.
'''
return context.get('title')
(I haven't tried implementing this in tags yet, so sorry for typos)
Then you'd use it in your html like so:
myfile.html
{% include_with_title _partials/header.html "My file!" %}
<body> ... </body>
_partials/header.html
<head>
<title>{% title %}</title>
</head>