Skip to content

Commit

Permalink
v.1.1.3
Browse files Browse the repository at this point in the history
* default block text if empty
  • Loading branch information
foo123 committed Mar 23, 2024
1 parent 0e13d74 commit 3122922
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/InTpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
/**
*
* InTpl: simple php templates supporting template inheritance
* @version 1.1.2
* @version 1.1.3
* https://github.com/foo123/InTpl
*
**/

if ( !class_exists('InTpl', false) )
if (!class_exists('InTpl', false))
{
class InTpl
{
const VERSION = '1.1.2';
const VERSION = '1.1.3';

private $_super = null;
private $_sprout = null;
Expand Down Expand Up @@ -92,9 +92,9 @@ public function end($name/*, $echo = true*/)
return $this;
}

public function block($name, $echo = true)
public function block($name, $echo = true, $defaultText = null)
{
$output = isset($this->_blocks[$name]) ? $this->_blocks[$name] : '';
$output = isset($this->_blocks[$name]) && strlen($this->_blocks[$name]) ? $this->_blocks[$name] : (is_string($defaultText) ? $defaultText : '');
if ($echo)
{
echo $output;
Expand All @@ -108,8 +108,7 @@ public function block($name, $echo = true)

public function render($data = array())
{
if (empty($this->tpl))
return '';
if (empty($this->tpl)) return '';

if (null === $this->found)
{
Expand All @@ -129,8 +128,7 @@ public function render($data = array())
}
}

if (! $this->found)
return '';
if (!$this->found) return '';

$this->data = (array) $data;
unset($data);
Expand Down
Binary file modified test/out
Binary file not shown.
1 change: 1 addition & 0 deletions test/tpl1.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@

<?php $this->start("b3") ?>(1 3)<?php $this->end("b3"); ?>

<?php $this->start("b4") ?><?php $this->end("b4"); ?>
1 change: 1 addition & 0 deletions test/tpl2.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@

<?php $this->start("b3"); ?>(2 3)<?php $this->super()->block("b3"); ?><?php $this->end("b3"); ?>

<?php $this->start("b4"); ?>(2 4)<?php $this->super()->block("b4", true, " default text"); ?><?php $this->end("b4"); ?>
1 change: 1 addition & 0 deletions test/tpl3.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@

<?php $this->start("b3"); ?>(3 3)<?php $this->super()->block("b3"); ?><?php $this->end("b3"); ?>

<?php $this->start("b4"); ?>(3 4)<?php $this->super()->block("b4"); ?><?php $this->end("b4"); ?>

0 comments on commit 3122922

Please sign in to comment.