-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
iQIcBAEBAgAGBQJSQeYfAAoJEJ9WpvTpw+EqQAEP/RZi3LPEu3TiJtamZMPrFQxl
WEV67vFhLuxWmiyM943hcnlCo+qpH24DNRyZ7Fh2s2Rs7Ba3MIf816A0F82JXWmS
BYtPbXe/RPYVfhSHSUaub5tw6KjWEXvKiQOI51W+tqOpa4fA9Oi+qaY+NjKXP/+o
/YfYgqW5l6YLVsoGFpFmdODBedgdEpkowH6/RgNieEgYTlOglBH49X0uFIXHnoDA
dRj0PO8NIpP6R7FQT4DsGKYx9D/ccJPt2zVpQtxjliEznPovbN/6soi2HM1G/Y1r
ZPRfhFuzXh7+Qtxrzj5u77OzTWmCP6PlTaOLF9H/h2r/Yz8AHw4IDHibdzKyXlDQ
FUpqDb1uHL9bgP5budXuyCG8jO8XECk78EaFt0+lFi0bFx4u33cQfBR/l5SNPqBy
Yduf1S85YBsJlziqG8OfRK15xWnGS5IBAU+CPLKt+hyjt40rhltOsdWm6tUlQEbb
3LUJOAWeAvXnxlmm1aAN6rOtvnHb+4SEdhTiDWF2lZql1lWgsKUtqwhXKDP+BBPr
POnnkB6R3oVZuF6KML+IZ3MMzWcI5F1alHOWBgI81HatudtLjcTmzyMxExJw8h6r
49d7Oo0fnWl6olvTfITqUmiiD5YTYpPBwlRxGTt5if1pR0uGW73R3+bYc3k9bGOo
qlaN5m/gv+0WVsCf+iAO
=AemT
-----END PGP SIGNATURE-----
I use it too.
Maybe it would be nice to document it somewhere.
Cheers,
Tom
Dne Tue, 24 Sep 2013 10:59:27 -0700 (PDT)
Warren Smith <warren@wandrsmith.net> napsal(a):
> On occasion, I've used the following technique in my django templates:
>
> # parent.html
>
> {% block someblock %}
> …stuff…
> {% if cool_optional_feature_is_enabled %}
> …optional stuff...
> {% endif %}
> …stuff...
> {% endblock %}
>
>
> # child.html
> {% extends "parent.html" %}
>
> {% block someblock %}
> {% with True as cool_optional_feature_is_enabled %}
> {{ block.super }}
> {% endwith %}
> {% endblock %}
>
>
> The cool thing is that this technique allows a child template to
> essentially enable a feature in the parent template. The same technique can
> also be used to disable a feature in the parent template, or really
> anything that can be driven from a context variable, since, as I understand
> it, that is what the with statement is doing: temporarily injecting a
> variable into the context within which the expressions in a chunk of
> template code are evaluated against.
>
> I was showing this to a colleague today and, though he thought it was neat,
> he had never seen it before and was concerned that it was not a mainstream
> use of the django template language. I did some cursory google searches and
> couldn't find any overt references to this ability either.
>
> My concern is that I may be relying on some undocumented side-effect of the
> way that blocks or the with statement are implemented and that, at some
> point in the future, this will be changed and all of my templates that use
> this will break.
>
>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment