relate icon indicating copy to clipboard operation
relate copied to clipboard

Chunk hack for jinja macro

Open dzhuang opened this issue 10 years ago • 2 comments

Works only for contents in chunks.

Jinja2 macro in repo file macros.jinja.

{% macro show_if_after(datespec) -%}
{%- if now is defined and parse_date_spec(datespec) > now %}
<div markdown="block" class="hidden">
{%- elif now is defined and parse_date_spec(datespec) <= now %}
<div markdown="block" >
{% endif %}
{{ caller() }}
</div>
{%- endmacro %}

The macro should be imported with with context, i.e.:

{% from "macros.jinja" import show_if_after with context %}

dzhuang avatar Oct 05 '15 16:10 dzhuang

As you can probably imagine, I'm not super-excited about this patch:

  • First, there's no real reason why Jinja in page chunks should behave differently from the way it does everywhere else.
  • Next, having to hand-write/import that macro every time seems kind of clunky.
  • Lastly, this ignores caching and therefore will show the wrong content at times.

I'll leave this open, as I think there are pieces that are worth keeping.

inducer avatar Oct 08 '15 04:10 inducer

Yes, you are right. Maybe the value of this PR is just to show what we can do if we can pass some markup context to the content rendered.

dzhuang avatar Oct 08 '15 05:10 dzhuang