OpenSourceEcon / oselab

Open Source Macroeconomics Lab Webpage built in Flask
9 stars 7 forks source link

More elegant macro imports #26

Closed asmockler closed 6 years ago

asmockler commented 6 years ago

All macros are imported at the top of our layout file and can therefore be used throughout all pages that use that layout.

Unfortunately, the same does not apply for macros within macros, which have to redefine their input. For example:

{% from 'components/floating_arrow_link.html' import floating_arrow_link %}

{% macro home_card(title, body, url) -%}
  <div class="home-card">
    <div class="home-card__content">
      <h4 class="home-card__heading">{{ title }}</h4>
      <p class="home-card__body-content">{{ body }}</p>
      <p class="home-card__body-content">
        {{ floating_arrow_link('Continue reading', url) }}
      </p>
    </div>
  </div>
{%- endmacro %}

If you remove the import and rely on the top-level import in the layout file, an error is thrown. It would be great if all macros could have access to other macros or at least macros that are imported before themselves in the layout file.

asmockler commented 6 years ago

See the explanation at the bottom of this section in the Flask docs