HP-Handy

 view release on metacpan or  search on metacpan

doc/jinja2_cheatsheet.EN.txt  view on Meta::CPAN

    </html>

  child.html:
    {% extends "base.html" %}
    {% block title %}My Page{% endblock %}
    {% block content %}<p>Hello</p>{% endblock %}

  Note: HP::Handy supports single-level inheritance only.
  super() (calling parent block content) is not supported.

[ 11. Macros ]

  Define:
    {% macro input(name, value="", type="text") %}
        <input type="{{ type }}" name="{{ name }}" value="{{ value }}">
    {% endmacro %}

  Call:
    {{ input("username") }}
    {{ input("password", type="password") }}

doc/jinja2_cheatsheet.FR.txt  view on Meta::CPAN


  base.html:
    {% block title %}Default{% endblock %}
    {% block content %}{% endblock %}

  child.html:
    {% extends "base.html" %}
    {% block title %}My Page{% endblock %}
    {% block content %}<p>Hello</p>{% endblock %}

[ 11. Macros ]

  {% macro input(name, value="", type="text") %}
      <input type="{{ type }}" name="{{ name }}" value="{{ value }}">
  {% endmacro %}

  {{ input("username") }}
  {{ input("password", type="password") }}

[ 12. with ]

doc/jinja2_cheatsheet.TL.txt  view on Meta::CPAN


  base.html:
    {% block title %}Default{% endblock %}
    {% block content %}{% endblock %}

  child.html:
    {% extends "base.html" %}
    {% block title %}My Page{% endblock %}
    {% block content %}<p>Hello</p>{% endblock %}

[ 11. Macro ]

  {% macro input(name, value="", type="text") %}
      <input type="{{ type }}" name="{{ name }}" value="{{ value }}">
  {% endmacro %}

  {{ input("username") }}
  {{ input("password", type="password") }}

[ 12. with ]

doc/jinja2_cheatsheet.TR.txt  view on Meta::CPAN


  base.html:
    {% block title %}Default{% endblock %}
    {% block content %}{% endblock %}

  child.html:
    {% extends "base.html" %}
    {% block title %}My Page{% endblock %}
    {% block content %}<p>Hello</p>{% endblock %}

[ 11. Macrolar ]

  {% macro input(name, value="", type="text") %}
      <input type="{{ type }}" name="{{ name }}" value="{{ value }}">
  {% endmacro %}

  {{ input("username") }}
  {{ input("password", type="password") }}

[ 12. with ]

doc/jinja2_cheatsheet.VI.txt  view on Meta::CPAN


  base.html:
    {% block title %}Default{% endblock %}
    {% block content %}{% endblock %}

  child.html:
    {% extends "base.html" %}
    {% block title %}My Page{% endblock %}
    {% block content %}<p>Hello</p>{% endblock %}

[ 11. Macro ]

  {% macro input(name, value="", type="text") %}
      <input type="{{ type }}" name="{{ name }}" value="{{ value }}">
  {% endmacro %}

  {{ input("username") }}
  {{ input("password", type="password") }}

[ 12. with ]

eg/01_hello_hp.pl  view on Meta::CPAN


my $tmpl2 = HP::Handy->new(template_dir => $tmpdir, auto_escape => 0);
print $tmpl2->render_string($child, {});
print "\n";

# Cleanup
unlink File::Spec->catfile($tmpdir, 'base.html');
rmdir $tmpdir;

######################################################################
# Example 5: Macro
######################################################################
print "\n=== Example 5: Macro ===\n";

my $src5 = <<'TMPL';
{% macro button(label, type="button") %}<button type="{{ type }}">{{ label }}</button>{% endmacro %}
{{ button("Submit", "submit") }}
{{ button("Cancel") }}
TMPL

print $tmpl->render_string($src5, {});
print "\n";

lib/HP/Handy.pm  view on Meta::CPAN

        $si += $len if $si < 0;
        $ei += $len if $ei < 0;
        $si = 0    if $si < 0;
        $ei = $len if $ei > $len;
        return [ @{$obj}[$si .. $ei - 1] ];
    }

    # Function/macro call: name(args)
    if ($expr =~ /^(\w+)\s*\(([^)]*)\)$/) {
        my ($fname, $argstr) = ($1, $2);
        # Macro call
        if (exists $self->{_macros}{$fname}) {
            return $self->_call_macro($fname, $argstr, $vars, '<expr>');
        }
        # Built-in functions
        if ($fname eq 'range') {
            return $self->_eval_range($argstr, $vars);
        }
    }

    # Variable lookup



( run in 0.988 second using v1.01-cache-2.11-cpan-40ba7b3775d )