Conditional include of templates

64 views
Skip to first unread message

mpeter

unread,
Jun 26, 2014, 7:11:14 AM6/26/14
to chica...@googlegroups.com


Hi,

Back in the good old days it was possible to put something like this into the template and have the included templates in view/music/...

{% if type=="spot" %}
        bbbbbbbb
        {% include "music/edit.html.spot" %}
{% elif type=="control" %}
        bbbbbbbb
        {% include "music/edit.html.control" %}
{% else %}
        cccccccc
        {% include "music/edit.html.default" %}
{% endif %}

After the mongodb connection issue was fixed last day I have upgraded CB and noticed that this no longer works. Specifically, it always includes (in this case) the edit.html.spot even if not the 1st branch runs (so I will see bbb or cccccc in the generated page.
Is there a way to restore the old behavior?


Thank you!

Best,
Peter

Kai Janson

unread,
Jun 26, 2014, 8:30:10 AM6/26/14
to chica...@googlegroups.com
Did you check the value of "type"?  It might be empty.

Sent from my non-google-device
--
You received this message because you are subscribed to the Google Groups "ChicagoBoss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chicagoboss...@googlegroups.com.
Visit this group at http://groups.google.com/group/chicagoboss.
To view this discussion on the web visit https://groups.google.com/d/msgid/chicagoboss/84c28755-8764-436e-8cf7-9dc9e455301e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

mpeter

unread,
Jun 26, 2014, 9:19:23 AM6/26/14
to chica...@googlegroups.com
Thanks for the suggestion.


As I mentioned the correct branch gets executed.
It must be something with the file names. Probably it gets confused by the samename.html.variation naming?

Peter

Kai Janson

unread,
Jun 26, 2014, 9:45:14 AM6/26/14
to chica...@googlegroups.com
As far as I remember templates should end in html... 

Sent from my non-google-device

mpeter

unread,
Jun 26, 2014, 10:16:01 AM6/26/14
to chica...@googlegroups.com
Not really if you are just including them. The above setup worked well in earlier CBs.
tried to rename the files (put the html to the end) but the behaviour did not change.

I have even tried to move those file out to view/lib/templates and include from there. Still it always renders the first included template even if one of the other two branches run (so in case of the example you can see that cccccc is in the source (branch 3 was run) yet the template from the first branch is included...).

I have renamed the files to like default spot and control so they have no common prefix. The problem is still there.


No matter what branch runs, it is always the include from the first branch that gets rendered (other things line the bbbbbb ccccc in the example are included from the correct branch)

It seems to be a serious problem.

Peter

mpeter

unread,
Jun 26, 2014, 10:19:48 AM6/26/14
to chica...@googlegroups.com
The actual setup is (just in case someone wants to reproduce): i have an edit.html template in view/music which just includes the correct body based on the values received from the controller. There is nothing more in my main template then what I have pasted into my first post.

mpeter

unread,
Jun 26, 2014, 10:23:07 AM6/26/14
to chica...@googlegroups.com
Also please notice that this is not a problem that has appeared wth yesterday's commit. It has been around for a while. The boss db mongo driver hat an issue so i as using an older version of CB until now (cant tell the exact version because i do not have the git metadata but at least 6 months old version.)

mpeter

unread,
Jun 26, 2014, 12:55:45 PM6/26/14
to chica...@googlegroups.com
I have managed to isolate the problem...


In the templates I have conditionally included  there is a {% extends "xy.html" %} directive

If I remove the extend lines, then the blocks (that should be rendered into the extended template) are rendered fine.

If I put back the extends line into the included templates, then it always displays the 1st template (older CB sued to render correctly )

All of the files are extending the same template so I have tried to move the extend into the main file like:

{% extends "music/base.html" %}

{% if type=="spot" %}
        bbbbbbbb
        {% include "music/edit.html.spot" %}
{% elif type=="control" %}
        bbbbbbbb
        {% include "music/edit.html.control" %}
{% else %}
        cccccccc
        {% include "music/edit.html.default" %}
{% endif %}


This resulted in none of the blocks being replaced (so the vanilla bae.html gets displayed). probably it is an erlydtl issue..? Or something else.


Peter

Jesse Gumm

unread,
Jun 26, 2014, 1:02:49 PM6/26/14
to chica...@googlegroups.com
This does sound like something ErlyDTL related. It's been undergoing
a lot of rapid development recently, and I'm uncertain if it's a bug
or a feature.

Could try submitting it as an issue to
https://github.com/erlydtl/erlydtl/issues to see if this was intended
or just a side effect of the recent refactoring.

-Jesse
> https://groups.google.com/d/msgid/chicagoboss/247dabc9-4943-4b60-907e-2ad9fcfddfda%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.



--
Jesse Gumm
Owner, Sigma Star Systems
414.940.4866 || sigma-star.com || @jessegumm

mpeter

unread,
Jun 26, 2014, 6:01:32 PM6/26/14
to chica...@googlegroups.com
Thanks, I will do so. It looks like this problem was introduced with erlydtl 0.9.1. as 0.9.0 works fine.

Peter

Péter Molnár

unread,
Jun 27, 2014, 4:00:59 AM6/27/14
to chica...@googlegroups.com
Just for reference, here is the opened erlydtl issue ticket for this.
https://github.com/erlydtl/erlydtl/issues/176
Reply all
Reply to author
Forward
0 new messages