<body>
<!--~~main_body show {~~-->
- <!--~~wfpl_messages {~~-->
- <!--~~ first {~~-->
- <div style="border: 2px solid red; background: #fbb; padding: 5px; margin: 20px 0px">
- <!--~~}~~-->
+ <!--~~wfpl_messages once_if {~~-->
+ <div style="border: 2px solid red; background: #fbb; padding: 5px; margin: 20px 0px">
+ <!--~~wfpl_messages {~~-->
<p style="font-size: 120%; padding: 5px; margin: 0px">~~data html~~</p>
- <!--~~ sep {~~-->
- <hr>
- <!--~~}~~-->
- <!--~~ last {~~-->
- </div>
- <!--~~}~~-->
+ <!--~~ sep {~~-->
+ <hr>
+ <!--~~}~~-->
+ <!--~~}~~-->
+ </div>
<!--~~}~~--><!--~opt_display {~-->
<!--~~display {~~-->
<div class="field"><!--~~jam_edit_id {~~--><a href="~file_name attr~?~file_name attr~_id=~~~file_name attr~_edit_id~~"><!--~~}~~--><!--~~jam_edit_id unset {~~--><a href="~file_name attr~"><!--~~}~~-->Cancel</a></div><!--~}~-->
<!--~}~--><!--~~}~~--><!--~opt_listing {~-->
- <!--~~listings {~~-->
+ <!--~~listings once {~~-->
<h2>~plural cap~ Listing</h2>
- <!--~~populated_listing {~~-->
+ <!--~~listings once_if {~~-->
<p><a href="~file_name~?~file_name~_new=1">[Add a new ~singular~]</a></p>
<table cellspacing="0" cellpadding="4" border="1" summary="">
- <!--~listing_headers {~--><th>~caption~</th><!--~}~--><th> </th><!--~~rows {~~-->
+ <!--~listing_headers {~--><th>~caption~</th><!--~}~--><th> </th><!--~~listings {~~-->
<tr><!--~listing_fields {~-->
- <td class="listing"><a href="~file_name~?~file_name~_<!--~opt_display unset {~-->edit_<!--~}~-->id=~~id~~"><!--~enc {~-->~~~name~ ~enc~~~<!--~}~--><!--~thumb {~--><!--~~~name~ nonempty {~~--><img src="~~~name~ thumb_src~~" width="~~~name~ thumb_width~~" height="~~~name~ thumb_height~~" alt=""><!--~~}~~--><!--~}~--></a></td><!--~}~-->
+ <td class="listing"><a href="~file_name~?~file_name~_<!--~opt_display unset {~-->edit_<!--~}~-->id=~~id~~"><!--~enc {~-->~~~name~ ~enc~~~<!--~~~name~ empty {~~--><em>(blank)</em><!--~~}~~--><!--~}~--><!--~thumb {~--><!--~~~name~ nonempty {~~--><img src="~~~name~ thumb_src~~" width="~~~name~ thumb_width~~" height="~~~name~ thumb_height~~" alt=""><!--~~}~~--><!--~}~--></a></td><!--~}~-->
<td><a href="~file_name~?~file_name~_delete_id=~~id~~" onclick="return confirm('Permanently delete?')">[delete this ~singular~]</a></td>
</tr><!--~~}~~-->
</table>
<!--~~}~~-->
- <!--~~empty_listing {~~-->
+ <!--~~listings once_else {~~-->
<p>No ~plural~ in database.</p>
<!--~~}~~-->
return $data;
}
-<!--~opt_listing {~-->
-# You may pass a "where clause" for the db query.
-function ~file_name~_display_listing($where = 'order by ~always_field~ limit 100') {
- $rows = db_get_assocs('~table_name~', 'id<!--~listing_fields_1 {~-->,~name~<!--~}~-->', $where);
- if($rows == false || count($rows) == 0) {
- tem_set('listings', array('empty_listing' => true));
- return;
- }
- # make sure there's something clickable
- foreach($rows as &$row) {
- if($row['~always_field~'] == '') {
- $row['~always_field~'] = '--';
- }
- }
- tem_set('listings', array(
- 'populated_listing' => true,
- 'rows' => $rows));
- return true;
-}
-<!--~}~-->
function ~file_name~_main() {<!--~opt_pass {~-->
if(!logged_in_as_admin()) {
$_REQUEST['url'] = this_url();
if(!$edit_id) {<!--~opt_listing {~-->
if(!isset($_REQUEST['~file_name~_new']) && !isset($_REQUEST['~always_field~'])) {
- ~file_name~_display_listing();
+ $listing_rows = db_get_assocs('~table_name~', 'id<!--~listing_fields_1 {~-->,~name~<!--~}~-->', 'order by ~always_field~ limit 100');
+ tem_set('listings', $listing_rows);
return;
}
<!--~}~-->
return $value;
}
+# 'empty' sections will be shown only if the corresponding data value is the
+# empty string
+function tem_auto_empty(&$value) {
+ if($value === '') return true;
+ return null;
+}
+
# 'nonempty' sections will not be shown if the corresponding data
# value is the empty string
function tem_auto_nonempty(&$value) {
return $value;
}
-# 'not' sections will not be shown if the corresponding data
+# 'unset' sections will not be shown if the corresponding data
# value is not set (opposite of default)
function tem_auto_unset(&$value) {
if($value === null) {
return $values;
}
+# 'once' sections are shown exactly once if the value is set (and not at all
+# otherwise.) This is useful when an array value would otherwise cause the
+# section to be displayed multiple times.
+function tem_auto_once(&$value) {
+ if($value === null) return null;
+ return true;
+}
+
+function tem_auto_once_if(&$value) {
+ if($value) return true;
+ return null;
+}
+
+# 'once' sections are shown exactly once if php evaluates the value to false
+# (and not at all otherwise.) This is useful when an array value would
+# otherwise cause the section to be displayed multiple times.
+function tem_auto_once_else(&$value) {
+ if($value) return null;
+ return true;;
+}
+