From af704c0a1cd5d1ad1317eb368e9c46bfa24dc8d0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C3=A9sar=20D=2E=20Rodas?= Date: Wed, 11 Aug 2010 02:00:56 -0400 Subject: [PATCH] - Added try_include tag; which behaves as `include` tag, except that the file to include may not exist. --- lib/Haanga.php | 11 +++++++++++ lib/Haanga/Extension/Tag/Tryinclude.php | 19 +++++++++++++++++++ tests/assert_templates/try_include.html | 3 +++ tests/assert_templates/try_include.tpl | 2 ++ tests/err_templates/err_invalid_tryinclude.tpl | 1 + tests/tmp/assert_templates/try_include.tpl.php | 17 +++++++++++++++++ 6 files changed, 53 insertions(+) create mode 100644 lib/Haanga/Extension/Tag/Tryinclude.php create mode 100644 tests/assert_templates/try_include.html create mode 100644 tests/assert_templates/try_include.tpl create mode 100644 tests/err_templates/err_invalid_tryinclude.tpl create mode 100644 tests/tmp/assert_templates/try_include.tpl.php diff --git a/lib/Haanga.php b/lib/Haanga.php index 3b25f3b..f3eb3aa 100644 --- a/lib/Haanga.php +++ b/lib/Haanga.php @@ -186,6 +186,17 @@ class Haanga } // }}} + // safe_load(string $file, array $vars, bool $return, array $blocks) {{{ + public static function Safe_Load($file, $vars = array(), $return=FALSE, $blocks=array()) + { + try { + return self::Load($file, $vars, $return, $blocks); + } Catch (Exception $e) { + return ""; + } + } + // }}} + // load(string $file, array $vars, bool $return, array $blocks) {{{ /** * Load diff --git a/lib/Haanga/Extension/Tag/Tryinclude.php b/lib/Haanga/Extension/Tag/Tryinclude.php new file mode 100644 index 0000000..be3852b --- /dev/null +++ b/lib/Haanga/Extension/Tag/Tryinclude.php @@ -0,0 +1,19 @@ +do_print($code, $exec); + + return $code; + + } +} diff --git a/tests/assert_templates/try_include.html b/tests/assert_templates/try_include.html new file mode 100644 index 0000000..523a059 --- /dev/null +++ b/tests/assert_templates/try_include.html @@ -0,0 +1,3 @@ + +Partial part + diff --git a/tests/assert_templates/try_include.tpl b/tests/assert_templates/try_include.tpl new file mode 100644 index 0000000..6352d72 --- /dev/null +++ b/tests/assert_templates/try_include.tpl @@ -0,0 +1,2 @@ +{% try_include "foobar-tpl.tpl" %} +{% try_include "assert_templates/partial.tpl" %} diff --git a/tests/err_templates/err_invalid_tryinclude.tpl b/tests/err_templates/err_invalid_tryinclude.tpl new file mode 100644 index 0000000..0b2cf0f --- /dev/null +++ b/tests/err_templates/err_invalid_tryinclude.tpl @@ -0,0 +1 @@ +{% try_include "foobar.tpl" as foo %} diff --git a/tests/tmp/assert_templates/try_include.tpl.php b/tests/tmp/assert_templates/try_include.tpl.php new file mode 100644 index 0000000..872748b --- /dev/null +++ b/tests/tmp/assert_templates/try_include.tpl.php @@ -0,0 +1,17 @@ +