https://bugs.underdark.nl/https://bugs.underdark.nl/favicon.ico2012-06-08T16:17:04ZBugtrackerµWeb - Bug #841: TemplateParser triggers TemplateKeyError if an "if" clause refers to a non-existing key, and no way to check if key exists before triggering if clause.https://bugs.underdark.nl/issues/841?journal_id=27992012-06-08T16:17:04ZElmer de Looffelmer@underdark.nl
<ul><li><strong>Status</strong> changed from <i>New</i> to <i>Resolved</i></li><li><strong>% Done</strong> changed from <i>0</i> to <i>70</i></li></ul><p>Applied in changeset <a class="changeset" title="Introduced {{ ifpresent }} construct to TemplateParser. This checks for presence of the provided ..." href="https://bugs.underdark.nl/projects/uweb/repository/revisions/52b0751e2acf">52b0751e2acf</a>.</p> µWeb - Bug #841: TemplateParser triggers TemplateKeyError if an "if" clause refers to a non-existing key, and no way to check if key exists before triggering if clause.https://bugs.underdark.nl/issues/841?journal_id=28002012-06-08T16:25:12ZElmer de Looffelmer@underdark.nl
<ul><li><strong>Category</strong> set to <i>TemplateParser</i></li><li><strong>Assignee</strong> changed from <i>Elmer de Looff</i> to <i>Niek Bergman</i></li><li><strong>Target version</strong> set to <i>µWeb alpha release</i></li></ul><p>Niek,</p>
<p>The <code>TemplateKeyError</code> you encountered should've been a <code>TemplateNameError</code>, which has been changed in <a class="changeset" title="Corrected wrong error class raised. Tags that are not found should always raise TemplateNameError..." href="https://bugs.underdark.nl/projects/uweb/repository/revisions/246">r246</a>. The {{ if }} construct does not and will not support referencing nonexistent template variables, because this would inevitably lead to disastrous surprises.</p>
<p>However, I've added a construct that does exactly what you want to do here, and that is checking the presence of a tag, or even its index:</p>
<pre><code class="html syntaxhl"><span class="CodeRay"><span class="tag"><html></span>
<span class="tag"><body></span>
{{ ifpresent [one] [two]}}
<span class="tag"><p></span>key number <span class="tag"><b></span>one<span class="tag"></b></span> AND <span class="tag"><b></span>two<span class="tag"></b></span> are provided<span class="tag"></p></span>
{{ elif [three] }}
<span class="tag"><p></span>one of keys <span class="tag"><b></span>one<span class="tag"></b></span> and <span class="tag"><b></span>two<span class="tag"></b></span> (or both) are missing, though <span class="tag"><b></span>three<span class="tag"></b></span> is provided<span class="tag"></p></span>
{{ else }}
<span class="tag"><p></span>none of the keys are provided<span class="tag"></p></span>
{{ endif }}
<span class="tag"></body></span>
<span class="tag"></html></span>
</span></code></pre>
<p>Please verify these changes work for you.</p> µWeb - Bug #841: TemplateParser triggers TemplateKeyError if an "if" clause refers to a non-existing key, and no way to check if key exists before triggering if clause.https://bugs.underdark.nl/issues/841?journal_id=28052012-06-11T08:51:17ZNiek Bergmanniek@underdark.nl
<ul></ul><p>Confirmed to work.</p> µWeb - Bug #841: TemplateParser triggers TemplateKeyError if an "if" clause refers to a non-existing key, and no way to check if key exists before triggering if clause.https://bugs.underdark.nl/issues/841?journal_id=30162012-07-19T14:43:33ZElmer de Looffelmer@underdark.nl
<ul><li><strong>Status</strong> changed from <i>Resolved</i> to <i>Closed</i></li><li><strong>% Done</strong> changed from <i>70</i> to <i>100</i></li></ul>