======================================================================
 HP::Handy Jinja2 Cheat Sheet                                                            [UZ] Uzbek
======================================================================

[ 1. Konstruktor ]

  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. Ajratuvchilar ]

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

[ 3. Oʻzgaruvchilar ]

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

[ 4. Filtrlar ]

  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. Testlar ]

  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. Shart ]

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

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

[ 7. for sikl ]

  {% 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. Qoʻshish ]

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

[ 10. Shablon merosi ]

  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. Makrolar ]

  {% 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. Ifodalar ]

  +  -  *  /  //  %  **   (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. Maxsus filtr va testlar ]

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

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

[ 16. Render usullari ]

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

[ 17. Rasmiy resurslar ]

  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

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