Coder Social home page Coder Social logo

Document Jinja2 extensions about hyde HOT 3 OPEN

hyde avatar hyde commented on May 23, 2024
Document Jinja2 extensions

from hyde.

Comments (3)

navilan avatar navilan commented on May 23, 2024

Hi,

Interesting. Can you give me an example of a template reuse outside of hyde?

I am wondering if the refer tag should translate to import and mark as a noop. An example would certainly clarify this.

Thanks
Lakshmi

from hyde.

alanhogan avatar alanhogan commented on May 23, 2024

Sure, what I’m doing right now is working with a Tornado instance which is using the Jinja2 framework and, initially, the FileSystemLoader set to use the same directory as all my Hyde templates.

The intention is to re-use the base and slightly more specific (e.g. two-column) layouts already used by Hyde, for more dynamic pages of the site.

So this runs into trouble for a couple reasons:

  1. Undefined media_url (easy enough to fix)…
  2. Jinja2 parse errors due to use of refer and apparently do as well, in the macros.j2 file that renders the nav in the default Hyde distribution (which I am using and appreciate).

It does initially make sense to map referimport and marknoop (without trying it)…

I can get rid of the refers from macros easily enough by splitting off the render_excerpt macro into a different file, leaving just common macros like render_nav.

But render_nav itself — which I would like to use in the Tornado environment as well — uses:

  {% do classes.append('active') if active -%}

and apparently Jinja2 doesn’t really get that by default. Thoughts?

from hyde.

navilan avatar navilan commented on May 23, 2024

I see. Yes, splitting off the macros file seems like a good idea - better than redefining the refer and mark tags for jinja2.

do is a jinja2 extension that needs to be configured.

Here is how default extensions are configured in hyde:
https://github.com/hyde/hyde/blob/master/hyde/ext/templates/jinja.py#L516-526

You can do the same wherever you initialize jinja2.

from hyde.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.