-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change extends tag to accept expressions #41
base: master
Are you sure you want to change the base?
Conversation
3af14f1
to
d1aeff1
Compare
Nice to make it more dynamic. I was also thinking of a "with" in the extends (or override) so that we can assign extra variables. Why did you only add a model call and not an expression? |
Agree, it could use an expression, but I could not find a way to do so in the compile_tokens({ok, {extends, ExtendsBlock, Elements}}, CState, _Options) ->
Blocks = find_blocks(Elements),
{Ws, BlockAsts} = compile_blocks(Blocks, CState),
{Ws1, ExtendsBlockAsts} = template_compiler_expr:compile(ExtendsBlock, CState, Ws), % <- here
% TODO: eval ExtendsBlockAsts and expects it to be a binary How about? |
Yes, and then evaluate the expression AST runtime, expecting a (binary) string. |
@mworrell, can you take a look at my changes? {% extends m.foo.template["base.tpl"]
title="Zotonic"
foo=`foo`
%}
{% block title %}{{ title }}{% endblock %}
{% block content %}
{% print foo %}
{% debug %}
{% endblock %} The template is rendered, but this is what is rendered: (zotonic@orp)1> =NOTICE REPORT==== 28-Mar-2023::13:52:59.103888 ===
DEBUG: {vars,#{auth_expires => 12460,auth_options => #{},
csp_nonce => <<"uakEb9kC2UxBjZupmdHG">>,foo => foo,id => 326,
q =>
[{<<"zotonic_dispatch">>,home},
{<<"zotonic_dispatch_path">>,[]},
{<<"zotonic_site">>,foo}],
session_id => <<"084e7de9-464d-6e07-c914-8acc874756df">>,
template => "home.tpl",title => <<"Zotonic">>,
zotonic_dispatch_file => <<"dispatch">>,
zotonic_dispatch_module => foo}}
=NOTICE REPORT==== 28-Mar-2023::13:52:59.104653 ===
DEBUG: {vars,#{auth_expires => 12460,auth_options => #{},code => en,
csp_nonce => <<"uakEb9kC2UxBjZupmdHG">>,id => 326,
q =>
[{<<"zotonic_dispatch">>,home},
{<<"zotonic_dispatch_path">>,[]},
{<<"zotonic_site">>,foo}],
session_id => <<"084e7de9-464d-6e07-c914-8acc874756df">>,
template => "home.tpl",z_language => en,
zotonic_dispatch_file => <<"dispatch">>,
zotonic_dispatch_module => foo}}
... The first log shows |
@williamthome I will have a look 👍 (Am on a couple of deadlines right now, so might take a couple of days...) |
Sure, no problem. Thanks! |
This PR adds a missing ability to resolve expressions in extends tag, e.g.
Motivation
The motivation is that today only strings are accepted by the extends tag.
Implementation notes
I tested this code in Zotonic, and it works.
I could not add tests because the
template_compiler_runtime:modal_call/4
does not resolve model calls.