Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

How to override Jinja2 block_start_string #43

Closed
elgalu opened this issue Apr 5, 2018 · 7 comments
Closed

How to override Jinja2 block_start_string #43

elgalu opened this issue Apr 5, 2018 · 7 comments
Assignees
Milestone

Comments

@elgalu
Copy link

elgalu commented Apr 5, 2018

Hi, I'm trying to override certain Jinja2 environment defaults like block_start_string:

import jinja2

jinja_env = jinja2.Environment(
    block_start_string = '<%',
    block_end_string = '%>',
    variable_start_string = '<<',
    variable_end_string = '>>'
)

I'm loading that extension file with yasha -e my_extension.py however it doesn't take effect as I don't know how to activate that jinja_env I'm creating.

Thanks for maintaining this project!

@kblomqvist
Copy link
Owner

kblomqvist commented Apr 5, 2018

Unfortunately that's not possible. Yasha's file extensions support only classes derived from jinja2.ext.Extension, not jinja2.Environment. However, I would like to support Environments too as I have had plans to use Yasha for Latex, see #31 and #33.

@elgalu
Copy link
Author

elgalu commented Apr 5, 2018

Thanks for the prompt response @kblomqvist and very glad to read its on your plans:)

@elgalu
Copy link
Author

elgalu commented Apr 5, 2018

Can you point me where in there source could I hard-code this settings? until is done "properly" ?

@kblomqvist
Copy link
Owner

https://github.com/kblomqvist/yasha/blob/master/yasha/yasha.py#L127

elgalu added a commit to elgalu/yasha that referenced this issue Apr 5, 2018
@kblomqvist
Copy link
Owner

A note to myself. Jinja's defaults could be overridden by local keys defined in Yasha's file extensions.

# extension.py
BLOCK_START_STRING = '{%'
BLOCK_END_STRING = '%}'
VARIABLE_START_STRING = '{{'
VARIABLE_END_STRING = '}}'
COMMENT_START_STRING = '{#'
COMMENT_END_STRING = '#}'
LINE_STATEMENT_PREFIX = None
LINE_COMMENT_PREFIX = None
TRIM_BLOCKS = False
LSTRIP_BLOCKS = False
NEWLINE_SEQUENCE = '\n'
KEEP_TRAILING_NEWLINE = False

@kblomqvist kblomqvist added this to the 4.3 milestone Apr 29, 2018
@kblomqvist kblomqvist self-assigned this Apr 29, 2018
kblomqvist added a commit that referenced this issue Apr 29, 2018
@kblomqvist
Copy link
Owner

kblomqvist commented Apr 29, 2018

@elgalu Could you try if https://github.com/kblomqvist/yasha#template-syntax works for you?

@elgalu
Copy link
Author

elgalu commented May 1, 2018

Works!! Thanks

@elgalu elgalu closed this as completed May 1, 2018
kblomqvist added a commit that referenced this issue May 1, 2018
While writing the test I realized that the output would
meet with my expectations if --keep-trailing-newline was
set by default.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants