1

In PHPTAL tal:condition can check is variable empty? Something like that:

< tag tal:condition="var" >Some text< /tag >

but the value of variable is like that:

<?php
$variable = '';
$Tpl->var = $variable;
?>

And it's a problem 'cause PHPTAL that value '' interpreting like not empty value and condition return true.

Next problem is using it when variable is a matrix. Then needed is tal:repeat and I don't know how check each elements of matrix in tal:condition

How fix it in PHPTAL side?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
kodziek
  • 41
  • 1
  • 7

3 Answers3

3
<tag tal:condition="php:!empty(var)">Some text</tag>
nuqqsa
  • 4,511
  • 1
  • 25
  • 30
  • You should really minimize the use of `php:` in templates as this defeats the purpose of separating view from logic and makes your templates less portable. – Explosion Pills Jul 21 '11 at 12:45
2

tal:condition evaluates '' and arrays with count($array)==0 as false.

If by martix you mean n-dimensional array, then you'll have to wrtite function that checks it the way you want and use it like in nuqqsa's answer.

Kornel
  • 97,764
  • 37
  • 219
  • 309
0

We can use the truetales to check if a variable is not empty. more information here

it works as PHP's !empty() construct.

< tag tal:condition="true:var" >Some text< /tag >

Hope this help future visitors of this question.

youssman
  • 1,514
  • 1
  • 17
  • 21