I have a small hierarchy of mako templates that go something like:
base.mako
<h1>${self.view()}</h1>
${listactions(self.mainactions)}
${self.body()}
<%def name="listactions(actions)">
<ul>
% for action in actions:
<li>${action}</li>
% endfor
</ul>
</%def>
clientsbase.mako
<%inherit file="base.mako"/>
<%def name="view()">Clients</%def>
<%
mainactions = [request.route_url('clientsnew')]
%>
clientsindex.mako
<%inherit file="clientsbase.mako"/>
This is the index
The problem is when I try to access the clients index view which renders clientsindex.mako I get the error AttributeError: Namespace 'self:/base.mako' has no member 'mainactions'.
What should be the proper way to do this? I've gone through the mako documentation and what I've found so far is I can use a module-level python block to declare mainactions and then in base.mako just do self.attr.mainactions. The problem with that is inside this block I don't have access to the request object.
I guess another question would be: in my case I'm using functions as view-callables, but let's say I've written a seperate clients.py view file which holds all the views related to clients. Is there a way to set sort of like controller-wide context variables from the clients.py file somehow? This way I could have a mainactions variable set in the template's context already without returning it in each view's dict.