File modules/template_engine/element/attribute/ConditionalAttribute.class.php

Last commit: Mon Feb 24 18:36:11 2020 +0100	Jan Dankert	Documentation added.
1 <?php 2 3 4 namespace template_engine\element\attribute; 5 6 7 use template_engine\element\attribute\SimpleAttribute; 8 use template_engine\element\Value; 9 10 /** 11 * A conditional attribute is an attribute whose existence depends on a condition. 12 * The condition would normally be an PHP expression. 13 */ 14 class ConditionalAttribute extends SimpleAttribute 15 { 16 /** The condition must be an valid PHP expression. 17 */ 18 protected $condition; 19 20 /** 21 * ConditionalAttribute constructor. 22 * @param $condition must be a valid PHP expression 23 * @param $name name of attribute 24 * @param $value value 25 */ 26 public function __construct($condition,$name,$value) 27 { 28 $this->condition = $condition; 29 parent::__construct($name,$value); 30 } 31 32 33 /** 34 * Rendering of the value. 35 * the value is wrapped into the conditional PHP expression. 36 */ 37 public function render() 38 { 39 return '<?php if('.$this->condition.'){ ?>'.parent::render().'<?php } ?>'; 40 } 41 }
Download modules/template_engine/element/attribute/ConditionalAttribute.class.php
History Mon, 24 Feb 2020 18:36:11 +0100 Jan Dankert Documentation added. Sat, 22 Feb 2020 22:23:01 +0100 Jan Dankert Refactoring: Enable Autoloading, Fix namespace structure.