Commit e31f671c85aea54f47a913398c1a03804d1565bc
1 parent
8edec41e
Put $main truly into the global scope using $GLOBALS.
If no contents are passed to the template, put up an error message. Add the ability to include standalone javascript in a page. git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@4057 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
20 additions
and
3 deletions
lib/templating/kt3template.inc.php
| @@ -18,6 +18,7 @@ class KTPage { | @@ -18,6 +18,7 @@ class KTPage { | ||
| 18 | /** resources are "filename"->1 to allow subcomponents to require items. */ | 18 | /** resources are "filename"->1 to allow subcomponents to require items. */ |
| 19 | var $js_resources = Array(); | 19 | var $js_resources = Array(); |
| 20 | var $css_resources = Array(); | 20 | var $css_resources = Array(); |
| 21 | + var $js_standalone = Array(); | ||
| 21 | 22 | ||
| 22 | /** context-relevant information */ | 23 | /** context-relevant information */ |
| 23 | var $errStack = Array(); | 24 | var $errStack = Array(); |
| @@ -88,7 +89,6 @@ class KTPage { | @@ -88,7 +89,6 @@ class KTPage { | ||
| 88 | // require that the specified JS file is referenced. | 89 | // require that the specified JS file is referenced. |
| 89 | function requireJSResource($sResourceURL) { | 90 | function requireJSResource($sResourceURL) { |
| 90 | $this->js_resources[$sResourceURL] = 1; // use the keys to prevent multiple copies. | 91 | $this->js_resources[$sResourceURL] = 1; // use the keys to prevent multiple copies. |
| 91 | - | ||
| 92 | } | 92 | } |
| 93 | 93 | ||
| 94 | // require that the specified JS files are referenced. | 94 | // require that the specified JS files are referenced. |
| @@ -102,6 +102,14 @@ class KTPage { | @@ -102,6 +102,14 @@ class KTPage { | ||
| 102 | function getJSResources() { | 102 | function getJSResources() { |
| 103 | return array_keys($this->js_resources); | 103 | return array_keys($this->js_resources); |
| 104 | } | 104 | } |
| 105 | + | ||
| 106 | + function requireJSStandalone($sJavascript) { | ||
| 107 | + $this->js_standalone[$sJavascript] = 1; // use the keys to prevent multiple copies. | ||
| 108 | + } | ||
| 109 | + // list the distinct js resources. | ||
| 110 | + function getJSStandalone() { | ||
| 111 | + return array_keys($this->js_standalone); | ||
| 112 | + } | ||
| 105 | 113 | ||
| 106 | /* css handling */ | 114 | /* css handling */ |
| 107 | // require that the specified CSS file is referenced. | 115 | // require that the specified CSS file is referenced. |
| @@ -190,6 +198,15 @@ class KTPage { | @@ -190,6 +198,15 @@ class KTPage { | ||
| 190 | 198 | ||
| 191 | /* final render call. */ | 199 | /* final render call. */ |
| 192 | function render() { | 200 | function render() { |
| 201 | + | ||
| 202 | + if (empty($this->contents)) { | ||
| 203 | + $this->contents = ""; | ||
| 204 | + } | ||
| 205 | + | ||
| 206 | + if (is_string($this->contents) && (trim($this->contents) === "")) { | ||
| 207 | + $this->addError("This page did not produce any content"); | ||
| 208 | + $this->contents = ""; | ||
| 209 | + } | ||
| 193 | 210 | ||
| 194 | if (!is_string($this->contents)) { | 211 | if (!is_string($this->contents)) { |
| 195 | $this->contents = $this->contents->render(); | 212 | $this->contents = $this->contents->render(); |
| @@ -224,6 +241,6 @@ class KTPage { | @@ -224,6 +241,6 @@ class KTPage { | ||
| 224 | } | 241 | } |
| 225 | 242 | ||
| 226 | /* set $main - this is used by the rest of the system. */ | 243 | /* set $main - this is used by the rest of the system. */ |
| 227 | -$main = new KTPage(); | 244 | +$GLOBALS['main'] = new KTPage(); |
| 228 | 245 | ||
| 229 | -?> | ||
| 230 | \ No newline at end of file | 246 | \ No newline at end of file |
| 247 | +?> |