yogthos / Selmer

A fast, Django inspired template system in Clojure.
Eclipse Public License 1.0
982 stars 114 forks source link

Using tags with {{ block.super }} #117

Open rwilson opened 8 years ago

rwilson commented 8 years ago

It seems {% style "some/style.css" %} tags don't render within {{ block.super }} calls, while explicit <link ... /> tags render as expected within a {{ block.super }} call.

For example, here's a cascading a->b->c hierarchy, each which includes 2 stylesheets in the block head: one named "*-style.css" rendered with a {% style ... %} tag, and the other "*-link.css" rendered with an explicit <link ... /> tag.

The final child, c, is the only one which renders a link from the "*-style.css" tag. The parents do not, even though each child calls {{ block.super }}. However, the explicit <link ... /> tags are rendered by the {{ block.super }} calls.

a.html

<!DOCTYPE html>
<html lang="en">
  <head>
    {% block head %}
    {% style "a-style.css" %}
    <link href="a-link.css" rel="stylesheet" />
    {% endblock %}
  </head>
  <body></body>
</html>

b.html

{% extends "a.html" %}

{% block head %}
{{ block.super }}
{% style "b-style.css" %}
<link href="b-link.css" rel="stylesheet" />
{% endblock %}

c.html

{% extends "b.html" %}

{% block head %}
{{ block.super }}
{% style "c-style.css" %}
<link href="c-link.css" rel="stylesheet" />
{% endblock %}

I just ran this in a repl for a quick test, here's the output:

user=> (println (selmer.parser/render-file "c.html" {}))
<!DOCTYPE html>
<html lang="en">
  <head>
    <link href="a-link.css" rel="stylesheet" />
    <link href="b-link.css" rel="stylesheet" />
    <link href="c-style.css" rel="stylesheet" type="text/css" />
    <link href="c-link.css" rel="stylesheet" />
  </head>
  <body></body>
</html>

Is it intended that style tags do not render within {{ block.super }}? If so, is it an intentional behavior that applies to other tags as well? I've only tested with style so far.

I also dumped a minimal repro here.

rwilson commented 8 years ago

After testing a few other cases, this applies to the style and include tags as well. Are tags intentionally unsupported via {{ block.super }}?

yogthos commented 8 years ago

Hi,

It's been a little while, I'll have to take a look at the specifics, but I suspect it's due to the fact that tags get run at compile time, while block.super operates at runtime on the compiled template.

TwiceII commented 8 years ago

Hi,

I confirm, it seems like tags in parent's block are ignored if called with {{block.super}}.