Thijs
April 12, 2018, 8:21am
1
The layout of a table is lost with following code:
Code :
|Wagen|Nummerplaat|Chassis|1e inschrijving|CO2|Fiscaal|Out op {% for wagenpark in company.custom.wagenpark %}{% capture wagenin %}{{ wagenpark.in-0 }}{% endcapture %}{% capture wagenout %}{{ wagenpark.out-0 }}{% endcapture %}{% if wagenout == "0.0" or wagenout >= beginboekjaar %}
|:-----|---:|---:|---:|---:|----:|----:|---:|
{% stripnewlines %}
|{{ wagenpark.wagen}}
|{{ wagenpark.nummerplaat }}
|{{ wagenpark.chassisnummer }}
|{{ wagenpark.eerste_inschrijving }}
|{{ wagenpark.co2 }}
|{% if wagenpark.brandstof == "Diesel" %}
{% if wagenpark.co2 < 61 %}100%{% endif %}
{% if wagenpark.co2 > 60 and wagenpark.co2 < 106 %}90%{% endif %}
{% if wagenpark.co2 > 105 and wagenpark.co2 < 116 %}80%{% endif %}
{% if wagenpark.co2 > 115 and wagenpark.co2 < 146 %}75%{% endif %}
{% if wagenpark.co2 > 145 and wagenpark.co2 < 171 %}70%{% endif %}
{% if wagenpark.co2 > 170 and wagenpark.co2 < 196 %}60%{% endif %}
{% if wagenpark.co2 > 195 %}50%{% endif %}
{% endif %}
{% if wagenpark.brandstof == "Benzine" %}
{% if wagenpark.co2 < 61 %}100%{% endif %}
{% if wagenpark.co2 > 60 and wagenpark.co2 < 106 %}90%{% endif %}
{% if wagenpark.co2 > 105 and wagenpark.co2 < 126 %}80%{% endif %}
{% if wagenpark.co2 > 125 and wagenpark.co2 < 156 %}75%{% endif %}
{% if wagenpark.co2 > 155 and wagenpark.co2 < 181 %}70%{% endif %}
{% if wagenpark.co2 > 180 and wagenpark.co2 < 206 %}60%{% endif %}
{% if wagenpark.co2 > 205 %}50%{% endif %}
{% endif %}
{% if wagenpark.brandstof == "Elektrisch" %}
120%
{% endif %}
|{{ wagenpark.out }}{% endstripnewlines %}
{% endif %}
{% endfor %}
sven
April 12, 2018, 8:56am
2
Hello @Thijs ,
I’d suggest putting the whole code between stripnewlines
and for each newline in the table, adding the tag {% newline %}
to it.
Like this for instance :
{% stripnewlines %}
|Wagen|Nummerplaat|Chassis|1e inschrijving|CO2|Fiscaal|Out op {% for wagenpark in company.custom.wagenpark %}{% capture wagenin %}{{ wagenpark.in-0 }}{% endcapture %}{% capture wagenout %}{{ wagenpark.out-0 }}{% endcapture %}{% if wagenout == "0.0" or wagenout >= beginboekjaar %}
{% if forloop.first %}
{% newline %}
|:-----|---:|---:|---:|---:|----:|----:|---:|
{% endif %}
{% newline %}
|{{ wagenpark.wagen}}
|{{ wagenpark.nummerplaat }}
|{{ wagenpark.chassisnummer }}
|{{ wagenpark.eerste_inschrijving }}
|{{ wagenpark.co2 }}
|{% if wagenpark.brandstof == "Diesel" %}
{% if wagenpark.co2 < 61 %}100%{% endif %}
{% if wagenpark.co2 > 60 and wagenpark.co2 < 106 %}90%{% endif %}
{% if wagenpark.co2 > 105 and wagenpark.co2 < 116 %}80%{% endif %}
{% if wagenpark.co2 > 115 and wagenpark.co2 < 146 %}75%{% endif %}
{% if wagenpark.co2 > 145 and wagenpark.co2 < 171 %}70%{% endif %}
{% if wagenpark.co2 > 170 and wagenpark.co2 < 196 %}60%{% endif %}
{% if wagenpark.co2 > 195 %}50%{% endif %}
{% endif %}
{% if wagenpark.brandstof == "Benzine" %}
{% if wagenpark.co2 < 61 %}100%{% endif %}
{% if wagenpark.co2 > 60 and wagenpark.co2 < 106 %}90%{% endif %}
{% if wagenpark.co2 > 105 and wagenpark.co2 < 126 %}80%{% endif %}
{% if wagenpark.co2 > 125 and wagenpark.co2 < 156 %}75%{% endif %}
{% if wagenpark.co2 > 155 and wagenpark.co2 < 181 %}70%{% endif %}
{% if wagenpark.co2 > 180 and wagenpark.co2 < 206 %}60%{% endif %}
{% if wagenpark.co2 > 205 %}50%{% endif %}
{% endif %}
{% if wagenpark.brandstof == "Elektrisch" %}
120%
{% endif %}
|{{ wagenpark.out }}
{% endif %}
{% endfor %}
{% endstripnewlines %}
More info on newlines here :
1. Stripnewlines tag
2. Stripnewlines and tables
3. Newline tag
Making sure your code is well structured is very important in every programming language. It builds logic into your code and you will profit from it in many ways:
It will help you to understand your code better
You won’t make errors as fast
When you do make an error, you’ll find if faster
It helps other people to understand your code faster
1. Stripnewlines tag
Before we go into the newline tag, we’ll have a look at the s…
Thijs
April 12, 2018, 9:26am
3
Dear @sven
Thanks!
One prolblem. If the if statement returns false at the first line, the lay out breaks:
sven
April 12, 2018, 9:59am
4
Breaking @Thijs ? Or did you mean that the headers are still visible even if there’s no data in your custom collection?
The better code is this :
{% stripnewlines %}
{% for wagenpark in company.custom.wagenpark %}
{% if forloop.first %}
| Wagen
| Nummerplaat
| Chassis
| 1e inschrijving
| CO2
| Fiscaal
| Out op {% capture wagenin %}{{ wagenpark.in-0 }}{% endcapture %}{% capture wagenout %}{{ wagenpark.out-0 }}{% endcapture %}{% if wagenout == "0.0" or wagenout >= beginboekjaar %}
{% newline %}
|:-----|---:|---:|---:|---:|----:|----:|---:|
{% endif %}
{% newline %}
|{{ wagenpark.wagen}}
|{{ wagenpark.nummerplaat }}
|{{ wagenpark.chassisnummer }}
|{{ wagenpark.eerste_inschrijving }}
|{{ wagenpark.co2 }}
|{% if wagenpark.brandstof == "Diesel" %}
{% if wagenpark.co2 < 61 %}100%{% endif %}
{% if wagenpark.co2 > 60 and wagenpark.co2 < 106 %}90%{% endif %}
{% if wagenpark.co2 > 105 and wagenpark.co2 < 116 %}80%{% endif %}
{% if wagenpark.co2 > 115 and wagenpark.co2 < 146 %}75%{% endif %}
{% if wagenpark.co2 > 145 and wagenpark.co2 < 171 %}70%{% endif %}
{% if wagenpark.co2 > 170 and wagenpark.co2 < 196 %}60%{% endif %}
{% if wagenpark.co2 > 195 %}50%{% endif %}
{% endif %}
{% if wagenpark.brandstof == "Benzine" %}
{% if wagenpark.co2 < 61 %}100%{% endif %}
{% if wagenpark.co2 > 60 and wagenpark.co2 < 106 %}90%{% endif %}
{% if wagenpark.co2 > 105 and wagenpark.co2 < 126 %}80%{% endif %}
{% if wagenpark.co2 > 125 and wagenpark.co2 < 156 %}75%{% endif %}
{% if wagenpark.co2 > 155 and wagenpark.co2 < 181 %}70%{% endif %}
{% if wagenpark.co2 > 180 and wagenpark.co2 < 206 %}60%{% endif %}
{% if wagenpark.co2 > 205 %}50%{% endif %}
{% endif %}
{% if wagenpark.brandstof == "Elektrisch" %}
120%
{% endif %}
|{{ wagenpark.out }}
{% endif %}
{% endfor %}
{% endstripnewlines %}
So the headers are only displayed when there’s data in your collection. Other than that, I don’t see issues with this code.
If you have, then perhaps you’ll need to post your code again I’m afraid.
Thijs
April 12, 2018, 11:19am
5
@sven
I meant that the headers are not bold if the first line of my fori-loop is not included in my forloop due the if-statement-> as you can see in my previous post.
sven
April 12, 2018, 11:22am
6
Ah okay… But that’s fixed with the last code by having the complete header in the forloop.first @Thijs .
this is okay for you?
Thijs
April 12, 2018, 12:19pm
7
@sven
With your code i get this: (with only the first one)
sven
April 12, 2018, 12:22pm
8
Can you post your code, as well perhaps the code you use to fill your collection? @Thijs
Because tested this already and it works for me; not sure why your table gets broken
Thijs
April 12, 2018, 12:33pm
9
{% capture Bboekjaar %}{{ period.year_start_date | date:'%d/%m/%Y' }}{% endcapture %}{% capture beginboekjaar %}{{ Bboekjaar-0 }}{% endcapture %}
{% capture Eboekjaar %}{{ period.year_end_date | date:'%d/%m/%Y' }}{% endcapture %}{% capture eindeboekjaar %}{{ Eboekjaar-0 }}{% endcapture %}
{% stripnewlines %}
{% for wagenpark in company.custom.wagenpark %}
{% if forloop.first %}
| Wagen
| Nummerplaat
| Chassis
| 1e inschrijving
| CO2
| Fiscaal
| Out op {% capture wagenin %}{{ wagenpark.in-0 }}{% endcapture %}{% capture wagenout %}{{ wagenpark.out-0 }}{% endcapture %}{% if wagenout == "0.0" or wagenout >= beginboekjaar %}
{% newline %}
|:-----|---:|---:|---:|---:|----:|----:|---:|
{% endif %}
{% newline %}
|{{ wagenpark.wagen}}
|{{ wagenpark.nummerplaat }}
|{{ wagenpark.chassisnummer }}
|{{ wagenpark.eerste_inschrijving }}
|{{ wagenpark.co2 }}
|{% if wagenpark.brandstof == "Diesel" %}
{% if wagenpark.co2 < 61 %}100%{% endif %}
{% if wagenpark.co2 > 60 and wagenpark.co2 < 106 %}90%{% endif %}
{% if wagenpark.co2 > 105 and wagenpark.co2 < 116 %}80%{% endif %}
{% if wagenpark.co2 > 115 and wagenpark.co2 < 146 %}75%{% endif %}
{% if wagenpark.co2 > 145 and wagenpark.co2 < 171 %}70%{% endif %}
{% if wagenpark.co2 > 170 and wagenpark.co2 < 196 %}60%{% endif %}
{% if wagenpark.co2 > 195 %}50%{% endif %}
{% endif %}
{% if wagenpark.brandstof == "Benzine" %}
{% if wagenpark.co2 < 61 %}100%{% endif %}
{% if wagenpark.co2 > 60 and wagenpark.co2 < 106 %}90%{% endif %}
{% if wagenpark.co2 > 105 and wagenpark.co2 < 126 %}80%{% endif %}
{% if wagenpark.co2 > 125 and wagenpark.co2 < 156 %}75%{% endif %}
{% if wagenpark.co2 > 155 and wagenpark.co2 < 181 %}70%{% endif %}
{% if wagenpark.co2 > 180 and wagenpark.co2 < 206 %}60%{% endif %}
{% if wagenpark.co2 > 205 %}50%{% endif %}
{% endif %}
{% if wagenpark.brandstof == "Elektrisch" %}
120%
{% endif %}
|{{ wagenpark.out }}
{% endif %}
{% endfor %}
{% endstripnewlines %}
<b><b>
|----|----|--20%--|----|----|----|----|----|----|----|---|---|---|---+{% fori wagenpark in company.custom.wagenpark %}
{% stripnewlines %}
|{% input wagenpark.wagen %}
|{% input wagenpark.nummerplaat %}
|{% input wagenpark.chassisnummer %}
|{% input wagenpark.soort as:select options:"Aankoop|Leasing|Renting" %}
|{% input wagenpark.aankoopfactuur as:file %}
|{% input wagenpark.contract as:file %}
|{% input wagenpark.co2 %}
|{% input wagenpark.cataloguswaarde as:currency %}
|{% input wagenpark.brandstof as:select options:"Diesel|Benzine|Elektrisch"%}
|{% input wagenpark.eerste_inschrijving as:date %}
|{% input wagenpark.btw_aftrekbaar as:percentage %}
|{% input wagenpark.in as:date %}
|{% input wagenpark.out as:date %}{% endstripnewlines %}{% endfori %}
sven
April 12, 2018, 3:02pm
10
It’s was this little thing right here that broke your table :
{% if wagenpark.brandstof == "Elektrisch" %}
120%
{% endif %}
|{{ wagenpark.out }}
{% endif %}
{% endfor %}
{% endstripnewlines %}
<b><b>
That never should be after a table; before and after a table always leave an empty line.
Should be good now like this:
{% if wagenpark.brandstof == "Elektrisch" %}
120%
{% endif %}
|{{ wagenpark.out }}
{% endif %}
{% endfor %}
{% endstripnewlines %}
<b><b>
Thijs
April 12, 2018, 3:45pm
11
I’m affraid it didn’t solve it.
First, I think the
{% if wagenout == “0.0” or wagenout >= beginboekjaar %}
is not in the right place anymore, because I get only the first line of the loop (it was changed with the stripnewlines):
Second, when i add a date to the first line in my foriloop:
It loses the layout and I should not by displayed in the forloop, because the date is 31/12/2016 ( {% if wagenout == "0.0" or wagenout >= beginboekjaar %}
)
Many thanks!
sven
April 12, 2018, 3:51pm
12
Overlooked that obviously, my bad…
this should fix it, because the capture are now out of the if forloop.first-statement as well putting the if-statement after the table :
{% capture Bboekjaar %}{{ period.year_start_date | date:'%d/%m/%Y' }}{% endcapture %}{% capture beginboekjaar %}{{ Bboekjaar-0 }}{% endcapture %}
{% capture Eboekjaar %}{{ period.year_end_date | date:'%d/%m/%Y' }}{% endcapture %}{% capture eindeboekjaar %}{{ Eboekjaar-0 }}{% endcapture %}
{% stripnewlines %}
{% for wagenpark in company.custom.wagenpark %}
{% if forloop.first %}
| Wagen
| Nummerplaat
| Chassis
| 1e inschrijving
| CO2
| Fiscaal
| Out op
{% newline %}
|:-----|---:|---:|---:|---:|----:|----:|---:|
{% endif %}
{% capture wagenin %}{{ wagenpark.in-0 }}{% endcapture %}
{% capture wagenout %}{{ wagenpark.out-0 }}{% endcapture %}
{% if wagenout == "0.0" or wagenout >= beginboekjaar %}
{% newline %}
|{{ wagenpark.wagen}}
|{{ wagenpark.nummerplaat }}
|{{ wagenpark.chassisnummer }}
|{{ wagenpark.eerste_inschrijving }}
|{{ wagenpark.co2 }}
|{% if wagenpark.brandstof == "Diesel" %}
{% if wagenpark.co2 < 61 %}100%{% endif %}
{% if wagenpark.co2 > 60 and wagenpark.co2 < 106 %}90%{% endif %}
{% if wagenpark.co2 > 105 and wagenpark.co2 < 116 %}80%{% endif %}
{% if wagenpark.co2 > 115 and wagenpark.co2 < 146 %}75%{% endif %}
{% if wagenpark.co2 > 145 and wagenpark.co2 < 171 %}70%{% endif %}
{% if wagenpark.co2 > 170 and wagenpark.co2 < 196 %}60%{% endif %}
{% if wagenpark.co2 > 195 %}50%{% endif %}
{% endif %}
{% if wagenpark.brandstof == "Benzine" %}
{% if wagenpark.co2 < 61 %}100%{% endif %}
{% if wagenpark.co2 > 60 and wagenpark.co2 < 106 %}90%{% endif %}
{% if wagenpark.co2 > 105 and wagenpark.co2 < 126 %}80%{% endif %}
{% if wagenpark.co2 > 125 and wagenpark.co2 < 156 %}75%{% endif %}
{% if wagenpark.co2 > 155 and wagenpark.co2 < 181 %}70%{% endif %}
{% if wagenpark.co2 > 180 and wagenpark.co2 < 206 %}60%{% endif %}
{% if wagenpark.co2 > 205 %}50%{% endif %}
{% endif %}
{% if wagenpark.brandstof == "Elektrisch" %}
120%
{% endif %}
|{{ wagenpark.out }}
{% endif %}
{% endfor %}
{% endstripnewlines %}
<b><b>
|----|----|--20%--|----|----|----|----|----|----|----|---|---|---|---+{% fori wagenpark in company.custom.wagenpark %}
{% stripnewlines %}
|{% input wagenpark.wagen %}
|{% input wagenpark.nummerplaat %}
|{% input wagenpark.chassisnummer %}
|{% input wagenpark.soort as:select options:"Aankoop|Leasing|Renting" %}
|{% input wagenpark.aankoopfactuur as:file %}
|{% input wagenpark.contract as:file %}
|{% input wagenpark.co2 %}
|{% input wagenpark.cataloguswaarde as:currency %}
|{% input wagenpark.brandstof as:select options:"Diesel|Benzine|Elektrisch"%}
|{% input wagenpark.eerste_inschrijving as:date %}
|{% input wagenpark.btw_aftrekbaar as:percentage %}
|{% input wagenpark.in as:date %}
|{% input wagenpark.out as:date %}{% endstripnewlines %}{% endfori %}
No issue with dates however
sven
April 12, 2018, 6:56pm
14
Glad to help; nice looking template