From 45683d4ba52755fcfefa5073f8e60a8e90a7c16b Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Mon, 25 Jul 2005 00:53:34 +0000 Subject: [PATCH] Merging the template-if-fix branch back onto head --- template.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/template.php b/template.php index e94ecf9..03341ad 100644 --- a/template.php +++ b/template.php @@ -464,6 +464,7 @@ class DB_Template // tag stack $stack = array(); $parsed = array(); + $elsestack = array(); for ($i = 0; $i < strlen($template); $i++) { @@ -475,6 +476,11 @@ class DB_Template //echo "OPEN `$i`: " . print_r($stack, true); } + // locate else tags + else if (substr($template, $i, strlen($tag_else)) == $tag_else) + { + array_push($elsestack, end($stack)); + } // do we have an end tag? else if (substr($template, $i, strlen($tag_end)) == $tag_end) { @@ -513,13 +519,13 @@ class DB_Template 'parsed' => '' ); - if (substr_count($conditional, $tag_else) == 0) + if (end($elsestack) == $last) { - $parsed["$depth"]["$last"]['parsed'] = '" . ((' . stripslashes($expression) . ') ? "' . $conditional . '" : "") . "'; + $parsed["$depth"]["$last"]['parsed'] = '" . ((' . stripslashes($expression) . ') ? "' . $conditional . '") . "'; } else { - $parsed["$depth"]["$last"]['parsed'] = '" . ((' . stripslashes($expression) . ') ? "' . $conditional . '") . "'; + $parsed["$depth"]["$last"]['parsed'] = '" . ((' . stripslashes($expression) . ') ? "' . $conditional . '" : "") . "'; } } } -- 2.43.5