JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
API CHANGE: change template varnames for messages
authorJason Woofenden <jason@jasonwoof.com>
Mon, 19 Sep 2011 18:40:39 +0000 (14:40 -0400)
committerJason Woofenden <jason@jasonwoof.com>
Mon, 19 Sep 2011 18:40:39 +0000 (14:40 -0400)
messages.php
metaform/site-template.html

index cf979d7..8c66ee2 100644 (file)
 # 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 <!--~message {~--> section with a
-# ~value html~ tag in it.
+# Just make sure your template has a <!--~$messages {~--> section with a
+# ~message html~ tag in it.
 #
 # Simple example:
 #
-#    <!--~messages {~-->
-#      <p>~value html~</p>
+#    <!--~$messages {~-->
+#       <p>~message html~</p>
 #    <!--~}~-->
 #
 # Full-featured example:
 #
-#    <!--~wfpl_messages {~-->
-#      <!--~ first {~-->
-#        <div style="border: 2px solid red; background: #fbb; padding: 5px; margin: 20px 0px">
-#      <!--~}~-->
-#          <p style="font-size: 120%; padding: 5px; margin: 0px">~data html~</p>
-#      <!--~ sep {~-->
-#          <hr>
-#      <!--~}~-->
-#      <!--~ last {~-->
-#        </div>
-#      <!--~}~-->
+#    <!--~$messages once_if {~-->
+#       <div id="wfpl_messages">
+#          <!--~$messages {~-->
+#             <p>~message html~</p>
+#             <!--~ sep {~-->
+#                <hr>
+#             <!--~}~-->
+#          <!--~}~-->
+#       </div>
 #    <!--~}~-->
 
 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');
 }
index bebfc07..78983c1 100644 (file)
                </nav>
 
                <div id="main-body">
-                       <!--~wfpl_messages once_if {~-->
+                       <!--~$messages once_if {~-->
                                <div id="wfpl_messages">
-                                       <!--~wfpl_messages {~-->
-                                               <p>~data html~</p>
+                                       <!--~$messages {~-->
+                                               <p>~message html~</p>
                                                <!--~ sep {~-->
                                                        <hr>
                                                <!--~}~-->