Skip to content

Commit

Permalink
Merge pull request #2 from le-phare/master
Browse files Browse the repository at this point in the history
Ok pour les modifs.
Merci
  • Loading branch information
hugokernel committed Feb 24, 2012
2 parents 9a3d1e3 + 922906f commit acd2db8
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 7 deletions.
12 changes: 5 additions & 7 deletions hyla_tpl.class.php
Expand Up @@ -457,15 +457,13 @@ private function _parseFuncVar($val, $type) {
}
}

// Variable exists ?
if (array_key_exists($name, $this->vars)) {
// Default with "empty" value
if ($default !== null && (!array_key_exists($name, $this->vars) || !strlen($this->vars[$name]))) {
$value = $default;
} elseif (array_key_exists($name, $this->vars)) {
$value = $this->vars[$name];
} else {
if ($default !== null) {
$value = $default;
} else {
return ($this->remove_unknow_var) ? null : '{$' . $name . '}';
}
return ($this->remove_unknow_var) ? null : '{$' . $name . '}';
}

// Function
Expand Down
23 changes: 23 additions & 0 deletions tests/index.php
Expand Up @@ -141,6 +141,29 @@ function hello($name = null) {

$t->render('block.always.called');

$lines = array(
0 => array(
'text' => null
),
1 => array(
'text' => ''
),
2 => array(
'text' => false
),
3 => array(
'text' => 0
),
4 => array(
'text' => 'some text'
),
);

foreach ($lines as $line) {
$t->setVar('line', $line);
$t->render('block_with_defaults');
}

// Affiche le résultat
echo $t->render();

Expand Down
25 changes: 25 additions & 0 deletions tests/tpl/main.tpl
Expand Up @@ -67,6 +67,31 @@ Hyla_Tpl version {$VERSION}
</blockquote>
<!-- END b1 -->

<h2>Blocks with default values</h2>
<pre><code>
$lines = array(
0 => array(
'text' => null
),
1 => array(
'text' => ''
),
2 => array(
'text' => false
),
3 => array(
'text' => 0
),
4 => array(
'text' => 'some text'
)
);
</code></pre>

<!-- BEGIN block_with_defaults -->
<p>line = {$line.text (<span class="ok">(default value)</span>)}</p>
<!-- END block_with_defaults -->

<a href="?dir={$dir}&lang={$lang_switch}">{_Switch lang} : {$lang_switch}</a>

<table width="50%" id="tree">
Expand Down

0 comments on commit acd2db8

Please sign in to comment.