Michael Kerrin

Web, Python, JavaScript and related technologies

pwt.jinja2js 0.6.0

with 2 comments

I have just uploaded a version 0.6.0 of pwt.jinja2js. This adds support for default values for macros arguments. So now you can do this:

{% macro defaultparam1(name = "World") -%}
Hello {{ name }}!
{%- endmacro %}

 

And you can call this like so to produce the desired output:

defaultparam1({}) -> "Hello World"
defaultparam({name: 'Michael'}) -> "Hello Michael"

 

About these ads

Written by mkerrin

2011, April 5 at 10:33 am

2 Responses

Subscribe to comments with RSS.

  1. I’m a really big fan of this project, I have been using it a lot.

    But one thing that is really bugging me is the lack of support for the “safe” filter.

    Also, is there any way to detect if the template is being executed using JavaScript? The objects I use on JavaScript are differently structured than the ones on Python, and I’d like to keep the code that unifies the structure inside the macro.

    mcilrain

    2011, April 7 at 7:16 am

    • Glad you are a fan.

      The “safe” filter is supported and works just like the Python version in Jinja2.

      Nope. There is no way to detect the execution environment and I don’t think their will be, in the end if you are trying to render different structures then I suggest using different templates / macros.

      mkerrin

      2011, April 7 at 2:12 pm


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: