Hello,
I have tried to do something like this:
<%def name="somefunction(arg1)">
Some function output with argument ${repr(arg1)}.
${caller.body()}
</%def>
<%block name="thing1">
<%local:somefunction arg1="blah">
<%block name="thing2">
Some content that I hope will be printed out.
</%block>
</%local:somefunction>
And Mako said that I wasn't allowed to put named blocks inside function calls. Why is this not allowed? Is it a technical limitation or an enforcement of an ideological restriction?
It seems to me that if blocks are implemented as global functions that Mako should simply be able to define the block, resolve the actual content of the block through the inheritance chain, if applicable, and then stick the resulting output into the function call content area. Would it not only be possible but also desirable for the above code to behave equivalently to the following (assuming this is the top-level template):
<%def name="somefunction(arg1)">
Some function output with argument ${repr(arg1)}.
${caller.body()}
</%def>
<%block name="thing1">
<%local:somefunction arg1="blah">
${thing2()}
</%local:somefunction>
</%block>
Some content, that I hope will be printed out.
</%def>
I am under the impression that the blocks are like "def" functions except:
1. They are always implemented as top-level functions in the resulting Python modules, rather than being able to be local, nested functions.
2. They may not take function arguments.
3. The first originating instance of a block is automatically and implicitly expanded with the top-most overriding block definition with the same name, and the result is inserted at the exact location of the original definition. (Regular defs functions are never automatically expanded at the sites of their definition.)
Are there any other conceptual or implementational differences between blocks and "def" functions that prevent blocks from being used inside of function content calls, or even, come to think of it, inside definitions for regular functions like below?
<%def name="thing1()">
<%block name="override_me">
Something to be overridden.
</%block>
</%def>
Love to hear thoughts of anyone who might be in the know. Thanks!
--Christopher