Kajiki and conditional content

38 views
Skip to first unread message

Craig Small

unread,
Aug 13, 2017, 9:13:39 AM8/13/17
to TurboGears
I'm converting from Mako to Kajiki and having problems with a if,then,else arrangement on my div


if w.fullwidth:                                                                                                                                      
<div class="col-md-12">                                                                                                                               
%elif w.fillrow:                                                                                                                                      
<div class="col-md-8 col-sm-8 col-xs-12">                                                                                                             
%else:                                                                                                                                                
<div class="col-md-4 col-sm-4 col-xs-12">                                                                                                             
%endif
stuff goes here
</div>

No matter what combination of py:if I try to use I get errors with the Kajiki xml engine. It seems to be almost but not quite the same and has a huge problem with conditional elements.

 - Craig

--
Craig Small             https://dropbear.xyz/     csmall at : enc.com.au
Debian GNU/Linux        https://www.debian.org/   csmall at : debian.org
Mastodon: @smal...@social.dropbear.xyz             Twitter: @smallsees  
GPG fingerprint:      5D2F B320 B825 D939 04D2  0519 3938 F96B DF50 FEA5

Alessandro Molina

unread,
Aug 14, 2017, 2:59:30 AM8/14/17
to TurboGears
I don't recall kajiki having a py:elif statement. It only supports py:if / py:else. For more complex conditionals py:switch / py:case / py:else should be used or you have to nest multiple if else conditions to achieve that.

--
You received this message because you are subscribed to the Google Groups "TurboGears" group.
To unsubscribe from this group and stop receiving emails from it, send an email to turbogears+unsubscribe@googlegroups.com.
To post to this group, send email to turbo...@googlegroups.com.
Visit this group at https://groups.google.com/group/turbogears.
For more options, visit https://groups.google.com/d/optout.

Craig Small

unread,
Aug 14, 2017, 3:25:50 AM8/14/17
to turbo...@googlegroups.com

I was trying to make the class of the div dependent on two variables.

X = class a
Not X and y = class b
Not X and not y = class C

The problem is you cannot have a conditional open tag and the close elsewhere. Eg

<py:if test="thing">
<div class="a">
</py:if>
<py:else>
<div class="b">
</py:else>
Words go here
</div>

It says that the div tag is closed by the py:if tag

Is the Right Way to put my "words go here" into a def and just repeat the div stack? E.g if div function /div /if

Or is there another way?


To unsubscribe from this group and stop receiving emails from it, send an email to turbogears+...@googlegroups.com.

To post to this group, send email to turbo...@googlegroups.com.
Visit this group at https://groups.google.com/group/turbogears.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "TurboGears" group.
To unsubscribe from this group and stop receiving emails from it, send an email to turbogears+...@googlegroups.com.

To post to this group, send email to turbo...@googlegroups.com.
Visit this group at https://groups.google.com/group/turbogears.
For more options, visit https://groups.google.com/d/optout.

Alessandro Molina

unread,
Aug 14, 2017, 10:05:13 AM8/14/17
to TurboGears
On Mon, Aug 14, 2017 at 9:25 AM, Craig Small <csm...@enc.com.au> wrote:

I was trying to make the class of the div dependent on two variables.

X = class a
Not X and y = class b
Not X and not y = class C

The problem is you cannot have a conditional open tag and the close elsewhere. Eg

Yep, absolutely, that's the whole idea behind Kajiki and Genshi, the whole thing must be valid xml so that it can never generate an invalid document as the result. 

<py:if test="thing">
<div class="a">
</py:if>
<py:else>
<div class="b">
</py:else>
Words go here
</div>

Use py:attrs or just "class=${a if thing else b}" ?

Craig Small

unread,
Aug 26, 2017, 6:37:06 AM8/26/17
to TurboGears
Thanks for that, it fixed that component of the templates.

Unfortunately, I'll probably have to go back to Mako because it requires some very strict requirements of the templates.  I haven't worked out why, but I get duplicate icons in my lists. Also things like <div class="clearfix" /> do some very strange things.

The killer is, Mako lets me template javascript, I just couldn't get Kajiki to handle it properly.

 - Craig


--
You received this message because you are subscribed to the Google Groups "TurboGears" group.
To unsubscribe from this group and stop receiving emails from it, send an email to turbogears+...@googlegroups.com.
To post to this group, send email to turbo...@googlegroups.com.
Visit this group at https://groups.google.com/group/turbogears.
For more options, visit https://groups.google.com/d/optout.

Alessandro Molina

unread,
Aug 26, 2017, 11:15:03 AM8/26/17
to TurboGears
On Sat, Aug 26, 2017 at 12:36 PM, Craig Small <csm...@enc.com.au> wrote:
Thanks for that, it fixed that component of the templates.

Unfortunately, I'll probably have to go back to Mako because it requires some very strict requirements of the templates.  I haven't worked out why, but I get duplicate icons in my lists. Also things like <div class="clearfix" /> do some very strange things.

How have you configured kajiki output? What do you mean by "some very strange things"?
I used kajiki as primary template engine for pretty big websites, and migrated multiple genshi projects to kajiki and so far it worked pretty well.
 
The killer is, Mako lets me template javascript, I just couldn't get Kajiki to handle it properly.

Do you have an example of what you are trying to do?
I used kajiki with React, Ractive and Angular so far without any major issue.

Alessandro 

Craig Small

unread,
Sep 3, 2017, 8:05:28 AM9/3/17
to TurboGears
Hi Alessandro,
  Took me a while to narrow it down, but it's font awesome doing the odd thing. For some reason it keeps repeating the icons, so I get about six instead of just the one.  I assume its some interaction between font awesome and another CSS file but to date I have not been able to separate out why I get this problem. I am also unsure why Kajiki would trigger this. The HTML from the server looks ok. Using span instead of i tags seems to fix it.

The main remaining problem now with Kajiki is that Mako allows me to have dynamic Javascript, while Kajiki doesn't seem to.
So I need things like this:
<script>
  var doughnutData = [
%for i,field in enumerate(w.graph_data):
    {
      value: ${field[1]},
color: "${w.graph_colors[i%len(w.graph_colors)]}"
    },
%endfor
    ];
  var my${w.id} = new Chart(document.getElementById("${w.id}").getContext("2d"))
.Doughnut(doughnutData);
</script>

This appears at the bottom of a template in Mako, any idea how you get something like this in Kajiki?

 - Craig


--
You received this message because you are subscribed to the Google Groups "TurboGears" group.
To unsubscribe from this group and stop receiving emails from it, send an email to turbogears+...@googlegroups.com.
To post to this group, send email to turbo...@googlegroups.com.
Visit this group at https://groups.google.com/group/turbogears.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages