macro / proc definition syntax
enthus1ast opened this issue · 3 comments
enthus1ast commented
jinja does it like this:
{% macro input(name, value="", type="text") %}
<input type="{{ type }}" value="{{ value|e }}" name="{{ name }}">
{% endmacro %}
{% macro textarea(name, value="", rows=10, cols=40) %}
<textarea name="{{ name }}" rows="{{ rows }}" cols="{{ cols
}}">{{ value|e }}</textarea>
{% endmacro %}
and then be called like this:
<dd>{{ input("username") }}</dd>
this syntax will work and could be used to create nim procedures.
But there also must be a way to support nims :
syntax like:
foo:
baa
this could be as simple as:
{% foo: %}
baa
{% end %}
respectively / alternative to the macro syntax:
{% proc baa(): string = %}
foo
{% end %}
the template body would then be expanded by nimja.
enthus1ast commented
this is now valid nimja:
{% proc foo(): string = %}
baa
{% end %}
{{ foo() }}
{% proc input(name: string, value="", ttype="text"): string = %}
<input type="{{ ttype }}" value="{{ value }}" name="{{ name }}">
{% end %}
{{ input("name", "value", ttype="text") }}
macro
is an alias for proc
{% macro textarea(name, value="", rows=10, cols=40): string = %}
<textarea name="{{ name }}" rows="{{ rows }}" cols="{{ cols
}}">{{ value }}</textarea>
{% end %}
{{ textarea("name", "value") }}
enthus1ast commented
block syntax works in theory, but is it useful?
what would be the usecase?
enthus1ast commented
close for now until usecase is found :)