|
TYPO3 API
SVNRelease
|
00001 <?php 00002 00003 /* * 00004 * This script belongs to the FLOW3 package "Fluid". * 00005 * * 00006 * It is free software; you can redistribute it and/or modify it under * 00007 * the terms of the GNU Lesser General Public License as published by the * 00008 * Free Software Foundation, either version 3 of the License, or (at your * 00009 * option) any later version. * 00010 * * 00011 * This script is distributed in the hope that it will be useful, but * 00012 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- * 00013 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser * 00014 * General Public License for more details. * 00015 * * 00016 * You should have received a copy of the GNU Lesser General Public * 00017 * License along with the script. * 00018 * If not, see http://www.gnu.org/licenses/lgpl.html * 00019 * * 00020 * The TYPO3 project - inspiring people to share! * 00021 * */ 00022 00023 /** 00024 * This view helper implements an if/else condition. 00025 * @see Tx_Fluid_Core_Parser_SyntaxTree_ViewHelperNode::convertArgumentValue() to find see how boolean arguments are evaluated 00026 * 00027 * = Conditions = 00028 * 00029 * As a condition is a boolean value, you can just use a boolean argument. 00030 * Alternatively, you can write a boolean expression there. 00031 * Boolean expressions have the following form: 00032 * XX Comparator YY 00033 * Comparator is one of: ==, !=, <, <=, >, >= and % 00034 * The % operator converts the result of the % operation to boolean. 00035 * 00036 * XX and YY can be one of: 00037 * - number 00038 * - Object Accessor 00039 * - Array 00040 * - a ViewHelper 00041 * Note: Strings at XX/YY are NOT allowed. 00042 * 00043 * <code title="condition example"> 00044 * <f:if condition="{rank} > 100"> 00045 * Will be shown if rank is > 100 00046 * </f:if> 00047 * <f:if condition="{rank} % 2"> 00048 * Will be shown if rank % 2 != 0. 00049 * </f:if> 00050 * <f:if condition="{rank} == {k:bar()}"> 00051 * Checks if rank is equal to the result of the ViewHelper "k:bar" 00052 * </f:if> 00053 * </code> 00054 * 00055 * = Examples = 00056 * 00057 * <code title="Basic usage"> 00058 * <f:if condition="somecondition"> 00059 * This is being shown in case the condition matches 00060 * </f:if> 00061 * </code> 00062 * 00063 * Everything inside the <f:if> tag is being displayed if the condition evaluates to TRUE. 00064 * 00065 * <code title="If / then / else"> 00066 * <f:if condition="somecondition"> 00067 * <f:then> 00068 * This is being shown in case the condition matches. 00069 * </f:then> 00070 * <f:else> 00071 * This is being displayed in case the condition evaluates to FALSE. 00072 * </f:else> 00073 * </f:if> 00074 * </code> 00075 * <output> 00076 * Everything inside the "then" tag is displayed if the condition evaluates to TRUE. 00077 * Otherwise, everything inside the "else"-tag is displayed. 00078 * </output> 00079 * 00080 * <code title="inline notation"> 00081 * {f:if(condition: someCondition, then: 'condition is met', else: 'condition is not met')} 00082 * </code> 00083 * <output> 00084 * The value of the "then" attribute is displayed if the condition evaluates to TRUE. 00085 * Otherwise, everything the value of the "else"-attribute is displayed. 00086 * </output> 00087 * 00088 * 00089 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later 00090 * @api 00091 */ 00092 class Tx_Fluid_ViewHelpers_IfViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractConditionViewHelper { 00093 00094 /** 00095 * renders <f:then> child if $condition is true, otherwise renders <f:else> child. 00096 * 00097 * @param boolean $condition View helper condition 00098 * @return string the rendered string 00099 * @author Sebastian Kurfürst <sebastian@typo3.org> 00100 * @author Bastian Waidelich <bastian@typo3.org> 00101 * @api 00102 */ 00103 public function render($condition) { 00104 if ($condition) { 00105 return $this->renderThenChild(); 00106 } else { 00107 return $this->renderElseChild(); 00108 } 00109 } 00110 } 00111 ?>
1.8.0