======================================================================
 HP::Handy Jinja2 Cheat Sheet                                                          [BN] Bengali
======================================================================

[ 1. কনস্ট্রাক্টর ]

  use HP::Handy;

  my $tmpl = HP::Handy->new(
      template_dir  => './templates',
      auto_escape   => 1,
      trim_blocks   => 0,
      lstrip_blocks => 0,
  );

  perl lib/HP/Handy.pm

[ 2. ডিলিমিটার ]

  {{ expr }}      output (HTML-escaped by default)
  {% tag %}       control tag
  {# comment #}   comment
  {%- tag -%}     whitespace control

[ 3. ভেরিয়েবল ]

  {{ name }}
  {{ user.email }}
  {{ items[0] }}
  {{ a.b.c }}

[ 4. ফিল্টার ]

  upper lower trim length escape safe default replace truncate
  join first last sort unique min max sum count map batch slice
  abs int title capitalize urlencode nl2br striptags tojson

  {{ name | upper }}
  {{ val  | default("n/a") }}
  {{ list | join(", ") }}
  {{ html | safe }}

[ 5. পরীক্ষা ]

  defined  none  string  number  sequence  mapping
  odd  even  divisibleby  upper  lower  equalto  in

  {% if x is defined %}
  {% if n is odd %}
  {% if x is not none %}

[ 6. শর্ত ]

  {% if condition %}
      ...
  {% elif other %}
      ...
  {% else %}
      ...
  {% endif %}

  {{ "yes" if flag else "no" }}

[ 7. for লুপ ]

  {% for item in list %}
      {{ loop.index }}: {{ item }}
  {% endfor %}

  {% for item in list if item != "" %}
      {{ item }}
  {% else %}
      (empty)
  {% endfor %}

  {% for key, value in mapping %}
      {{ key }}: {{ value }}
  {% endfor %}

  loop.index  loop.index0  loop.first  loop.last
  loop.length  loop.odd  loop.even  loop.revindex

[ 8. set ]

  {% set x = 42 %}
  {% set s = "Hello, " ~ name %}

[ 9. অন্তর্ভুক্ত করুন ]

  {% include "header.html" %}
  {% include "opt.html" ignore missing %}

[ 10. টেমপ্লেট ইনহেরিটেন্স ]

  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 input(name, value="", type="text") %}
      <input type="{{ type }}" name="{{ name }}" value="{{ value }}">
  {% endmacro %}

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

[ 12. with ]

  {% with x = 10, y = 20 %}
      {{ x + y }}
  {% endwith %}

[ 13. raw ]

  {% raw %}
      {{ not rendered }}
  {% endraw %}

[ 14. এক্সপ্রেশন ]

  +  -  *  /  //  %  **   (arithmetic)
  ~                        (string concat)
  ==  !=  <  >  <=  >=    (comparison)
  and  or  not             (logic)
  in  not in               (membership)
  a if cond else b         (ternary)
  range(stop)  range(start, stop, step)

[ 15. কাস্টম ফিল্টার ও টেস্ট ]

  $tmpl->add_filter('double', sub { $_[0] . $_[0] });
  # {{ text | double }}

  $tmpl->add_test('positive', sub { defined $_[0] && $_[0] > 0 });
  # {% if n is positive %}

[ 16. রেন্ডার মেথড ]

  my $html = $tmpl->render_file('index.html', \%vars);
  my $html = $tmpl->render_string($source, \%vars);

[ 17. অফিসিয়াল রিসোর্স ]

  Jinja2: https://jinja.palletsprojects.com/
  HP::Handy:   https://metacpan.org/dist/HP-Handy
  HTTP::Handy: https://metacpan.org/dist/HTTP-Handy
  DB::Handy:   https://metacpan.org/dist/DB-Handy

======================================================================
