From: Jason Woofenden Date: Mon, 19 Sep 2011 18:40:39 +0000 (-0400) Subject: API CHANGE: change template varnames for messages X-Git-Url: https://jasonwoof.com/gitweb/?p=wfpl.git;a=commitdiff_plain;h=2d753b1cb86b98e2995476b74f47cb5663670e4d API CHANGE: change template varnames for messages --- diff --git a/messages.php b/messages.php index cf979d7..8c66ee2 100644 --- a/messages.php +++ b/messages.php @@ -23,36 +23,37 @@ # Just call message("message here") whenever you have something to report. # # -# Once a template is loaded, call display_messages(). run.php will do that -# automatically after your main function returns, so long as you require_once -# this file. +# Once a template is loaded, call display_messages(). run.php will call +# display_messages() for you automaticallly after your main function returns +# (so long as you require_once this file.) If you want these messages to +# persist accross browser redirects, then you should +# require_once("code/wfpl/session_messages.php") # -# Just make sure your template has a section with a -# ~value html~ tag in it. +# Just make sure your template has a section with a +# ~message html~ tag in it. # # Simple example: # -# -#

~value html~

+# +#

~message html~

# # # Full-featured example: # -# -# -#
-# -#

~data html~

-# -#
-# -# -#
-# +# +#
+# +#

~message html~

+# +#
+# +# +#
# require_once('code/wfpl/template.php'); +# call this to display a message function message($msg) { if(!isset($GLOBALS['wfpl_messages'])) { $GLOBALS['wfpl_messages'] = array(); @@ -61,6 +62,7 @@ function message($msg) { $GLOBALS['wfpl_messages'][] = $msg; } +# destructive function get_messages() { if(!isset($GLOBALS['wfpl_messages'])) { $messages = array(); @@ -76,11 +78,10 @@ function get_messages() { return $messages; } -# for old-style templates -function display_messages(&$tem = NULL, $key = 'wfpl_messages') { - if($tem) { - $tem->data[$key] = columnize(get_messages()); - } else { - $GLOBALS['wfpl_template']->data[$key] = columnize(get_messages()); +# called automatically by run.php +function display_messages(&$tem = NULL, $key = '$messages') { + if(!$tem) { + $tem = &$GLOBALS['wfpl_template']; } + $tem->data[$key] = columnize(get_messages(), 'message'); } diff --git a/metaform/site-template.html b/metaform/site-template.html index bebfc07..78983c1 100644 --- a/metaform/site-template.html +++ b/metaform/site-template.html @@ -26,10 +26,10 @@
- +
- -

~data html~

+ +

~message html~