class Crinja::Tag::Macro

Overview

Macros are comparable with functions in regular programming languages. They are useful to put often used idioms into reusable functions to not repeat yourself (“DRY”).

Here’s a small example of a macro that renders a form element:

{% macro input(name, value='', type='text', size=20) -%}
    <input type="{{ type }}" name="{{ name }}" value="{{
        value|e }}" size="{{ size }}">
{%- endmacro %}

The macro can then be called like a function in the namespace:

{{ input('username') }}

See Jinja2 Template Documentation for details.

Defined in:

lib/tag/macro.cr

Instance Method Summary

Instance methods inherited from class Crinja::Tag

end_tag : String? end_tag, has_block?(node : TagNode) has_block?, interpret_output(renderer : Renderer, tag_node : TagNode) interpret_output, to_s(io) to_s

Instance Method Detail

def end_tag : String? #

[View source]
def interpret_output(renderer : Renderer, tag_node : TagNode) #

[View source]
def name : String #

[View source]