As it turns out, you can't use "for" as an argument/tag element attribute
with mako. At least not when inheriting the namespace into templates
at arbitrary depth.
<%def name="user_row(tab_index, havecreds, user)">
<tr>
- <%self.lib:td_label>Username</%self.lib:td_label>
+ <%self.lib:td_label for_id="user_id">Username</%self.lib:td_label>
% if havecreds:
<td><span id="user_id">${user}</span></td>
% else:
<%def name="password_row(tab_index, havecreds)">
% if not havecreds:
<tr>
- <%self.lib:td_label>Password</%self.lib:td_label>
+ <%self.lib:td_label for_id="password_id">Password</%self.lib:td_label>
<%self.lib:td_input tab_index="${tab_index}">
<input name="password"
tabindex="${tab_index.val}"
<%def name="database_row(tab_index)">
<tr>
- <%self.lib:td_label>Database</%self.lib:td_label>
+ <%self.lib:td_label for_id="db_id">Database</%self.lib:td_label>
<%self.lib:td_input tab_index="${tab_index}">
<input name="db"
tabindex="${tab_index.val}"
## Table data
-<%def name="td_label()">
+<%def name="td_label(for_id=None)">
<td class="label">
- <label for="user_id">${capture(caller.body) | trim}:</label>
+ <%
+ for_attr = ''
+ if for_id is not None:
+ for_attr = f'for="{for_id}"'
+ %>
+ <label ${for_attr}>${capture(caller.body) | trim}:</label>
</td>
</%def>