I was able to set the html title tag for every post of my blog (Thanks
Morgan Goose for this!), but i'm
still not getting an unique title tag for pages that are not posts
(about.html.mako, for example). Any hint how to get it? I guess it's
needed to set the title on the page, for example
# about.html.mako
<%
page_title = "About"
%>
[other page stuff]
But how to get this info on _templates/head.mako??? I tried Morgan's
approach and it's not working:
# head.mako
[stuff]
% if hasattr(self, "page_title"):
<title>${self.page_title}</title>
[moar stuff]
Thanks in advance!
I was able to set the html title tag for every post of my blog (Thanks
Morgan Goose for this!)
The way I generated the name was by doing:
path = bf.template_context.render_path
page_title = path.split('/')[0].capitalize()
There's seems to be no trivial way to get the a page's title unlike posts, however, there's a way where you can get the title, here's how I did it.
[...]
I might be hijacking the thread, but I've run into this issue in a more general way (disclaimer: I'm mostly a back end application programmer, so I might be trying to do the wrong thing here on the frontend). E.g.: on certain pages, I would like to include some extra javascript or css files in the page; or customize the <title> *while retaining the site wide title settings *, e.g.: About us | [site configured title] - so that if I change the general wording of the title in the config/head.mako I don't have to remember to grep across all files to ensure the customized pages are consistent.Also, I try to minimize the amount of python code I need to write in my templates, since I've found that rather helps when working with non-developers (e.g.: designers). A solution similar to django's template inheritance https://docs.djangoproject.com/en/dev/topics/templates/#template-inheritance would be nice - though we might not need something so advanced/complicatedAnd of course, this might be possible in mako too - let me know if so (or give me some pointers where to start searching).
Just 2c (until I will find enough free time to dive into the code),PeterOn Wed, Nov 14, 2012 at 11:42 AM, EJelome <eje...@gmail.com> wrote:
There's seems to be no trivial way to get the a page's title unlike posts, however, there's a way where you can get the title, here's how I did it.[...]path = bf.template_context.render_path
page_title = path.split('/')[0].capitalize()
--
You received this message because you are subscribed to the Google Groups "blogofile-discuss" group.To post to this group, send email to blogofil...@googlegroups.com.
To unsubscribe from this group, send email to blogofile-disc...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/blogofile-discuss?hl=en.
There's a couple of ways in Mako to to this sort of thing, the %block construct, and %def.
I typically have a site.mako template that has all the site-wide HTML boilerplate, links and scripts needed on every page (e.g. jQuery, site CSS, etc.). In that template I put a block like:
<title><%block name="title">Site Title</%block></title>
Other templates inherit from site.mako (maybe through multiple layers of inheritance), but they can override the default site title with:
<%block name="title">Page Title</%block>