abw / Template2

Perl Template Toolkit v2
http://template-toolkit.org/
146 stars 94 forks source link

Exiting a MACRO early #299

Open randyl opened 2 years ago

randyl commented 2 years ago

Several times I've wanted to exit a MACRO early if some condition is met. I keep thinking RETURN will do this, but it exits the template, not the macro. I guess that works if the macro is in its own template, but many times I have a macro that exists only in the template that uses it.

I'm looking for something like this:

MACRO output_section( value ) BLOCK;
    IF value == 0;
        # display short amount of html for special case
        EXIT;  # exit this macro/block
    END;

    # display lots of html for section
END;

# display main html
output_section( 4 );
output_section( 0 );