1

So I'm using dotLiquid (1.8.0) in my Project to create some HTML-Templates which are used to create PDFs via EO.pdf

So basically, I want to check if the given dates of an array of Days (== Dates) are in one week and add a page break after each week.

To make my problem more clear, here's the relevant code first:

{% for day in plan.Days %}
   ...
    <table>
        <tbody>
            <tr class="footnote">
                <td>** Debug:</td>
            </tr>
            <tr><td>Index:  {{forloop.index}}, DateTypeChoice: {{plan.DateTypeChoice }}</td> <!-- just debug-statements -->
            </tr>
        </tbody>
    </table>

    {% assign endofweek = forloop.index | modulo: plan.DateTypeChoice %}
    <p>endofweek: {{endofweek}}</p>
    {%if endofweek == 0 %}
    <p>"dubididu Index: " {{forloop.index}}</p>
    <div style="page-break-before: always"></div>
    {% endif %}
{% endfor %}
</body>
</html>

plan.DateTypeChoiceis an integer-value containing the number of days of a week (5 or 7 days). It is defined in my Drop-Model as

    public int DateTypeChoice { get; set; }

Now in my test-scenario, the debug-statements (Index and DateTypeChoice) are showing the values I expect, but actually endofweek contains for example (see below) 5 instead of 0and I don't know why it is.

example output is:

** Debug:
Index:  5, DateTypeChoice: 5
endofweek: 5 // This should be 0 imho

I also tried to put brackets to the assignment, like

    {% assign endofweek = (forloop.index | modulo: plan.DateTypeChoice) %}

but then I get an error thrown (value can'T be NULL).

I hope someone could help me out here. Perhaps I am using modulo wrong? As I know, forloop.index is a numeric value and numeric values given to the template from the model are treated as numeric values by the parser, too, so I am out of ideas.

Edit:

Based on this thread, I tried it with capturing instead of assigning, but same result. Code:

{% capture endofweek %} {{ forloop.index | modulo: plan.DateTypeChoice }}{% endcapture %}

    <p>"endofweek: " {{endofweek}}</p> //again 5 :-(
    {%if endofweek == 0 %}

Help is really appreciated here :-)

4

1 回答 1

1

最后我找到了解决方案...

重新分析后,我发现我的模板中实际上没有应用过滤器。也就是说,我在这里找到了解决方案。

我正在使用

Template.NamingConvention = new DotLiquid.NamingConventions.CSharpNamingConvention();

也是,所以在改成modulo:大写Modulo字母M后,一切正常..叹息

于 2015-09-09T10:36:29.533 回答