All Examples are included in the Beilpuz archive.
include_once('../Beilpuz.php'); $template = new BpTemplate('static main document.html'); echo $template->render();
<html> <bp:include template="static title.html"/> <body>Im the main document. My title was declared by template 'static title.html'. </body></html>
include('../Beilpuz.php'); $template = new BpTemplate('arrays and objects.html'); $template->setValue('animals', Array('Katze', 'Affe', 'Kuh')); $template->setValue('entry', new Entry); echo $template->render(); class Entry { public function getNow() { return time(); } public $nr = 3; public $array = Array('Eins','Zwei','Drei','Vier'); }
<html><body> First animal: <bp:$animals[0]/><br> All Animals:<br> <ul> <bp:foreach in="animals" as="test" index="number" direct="true"> <li><bp:$number/>. <bp:$test/></li> </bp:foreach> </ul> Object: <ul> <li><bp:$entry.getNow()/></li> <li><bp:$entry.nr/></li> <li><bp:$entry.array[3]/></li> </ul> </body></html>
include('../Beilpuz.php'); $template = new BpTemplate('own signatures.html'); echo $template->render();
<html><body> Im custom signature:<br> <hr><bp:hello name="Welt" use="include/hello_signature"/> <hr><bp:hello name="Dame" direct="true"/> </body></html>
function bp_hello($sig, $template) { if ($sig->getAttribute('direct') === true) { return Beilpuz::PHP_BEGIN . ' echo \'direct: Hallo liebe ' . $sig->getAttribute('name') . '\'' . Beilpuz::PHP_END; } else { return 'Hallo liebe ' . $sig->getAttribute('name') . '<br>'; } }
include('../Beilpuz.php'); $template = new BpTemplate('shared values.html'); echo $template->render();
<html> <bp:include template="shared title.html" use="include/set_value" shared_values="true"/> <body> Im a shared value, defined from my title template: <bp:$tellmesomething/> </body></html>
function bp_set_value($sig, $template) { $template->setValue('tellmesomething', 'Nachts ist es kälter als draußen'); }
include('../Beilpuz.php'); $template = new BpTemplate('signature attributes.html'); echo $template->render();
<html><body> A div from signature with attributes: <bp:draw_content_div width="300" height="200" color="green" border="true" use="include/draw_div"/> </body></html>
function bp_draw_content_div($sig, $template) { $content = ''; if ($sig->tpl !== null) { $content = $sig->tpl->render(); } $render = '<div style="width:' . $sig->getAttribute('width') . 'px;height:'.$sig->getAttribute('height').'px;background-color:' . $sig->getAttribute('color'); if ($sig->getAttribute('border') === true) $render .= ';border-width:2px;border-color:#000000;border-style:solid;'; $render .= '">' . $content . '</div>'; $sig->setAttribute('done', true); return $render; }
include('../Beilpuz.php'); Beilpuz::allowCacheKey('dummy'); $template = new BpTemplate('cached template.html'); echo $template->render();
<html><bp:include template="static title.html" cacheable="true"/> <body> Im a cached template, created at: <bp:current_time cacheable="true"/><br> You have to change my master template or delete me for recreation.<br><br> Im a non-cached signature: <bp:current_time use="include/current_time"/> </body></html>
function bp_current_time($sig) { return date('r'); }
function getmicrotime() { list($usec, $sec) = explode(" ",microtime()); return ((float)$usec + (float)$sec); } $start_time = getmicrotime(); include('../Beilpuz.php'); $template = new BpTemplate('signature content.html'); echo $template->render(); echo '<font size=1>time:' . (getmicrotime() - $start_time).'</font>';
<html><body> A signature with content: <bp:draw_content_div width="500" height="300" color="red" border="false" use="include/draw_div"> <bp:draw_content_div width="400" height="260" color="yellow" border="false"> Im content: <bp:draw_content_div width="10" height="10" color="green" border="true"/> <bp:draw_content_div width="10" height="10" color="green" border="true"/> <bp:draw_content_div width="10" height="10" color="green" border="true"/> <bp:draw_content_div width="10" height="10" color="green" border="true"/> End </bp:draw_content_div> <bp:draw_content_div width="400" height="20" color="blue" border="false"> hello world </bp:draw_content_div> </bp:draw_content_div> </body></html>
include('../Beilpuz.php'); $template = new BpTemplate('conditions.html'); $template->setValue('headline','Hello'); $template->setValue('subject','World'); echo $template->render(); $template->setValue('subject','Kitty'); echo $template->render();
<bp:if value="headline"> <h1><bp:$headline/></h1> <bp:if value="subject" is="World"> <strong><bp:$subject/></strong> </bp:if> <bp:if value="subject" is="Kitty"> <font color="#FFAACC"><bp:$subject/></font> </bp:if> </bp:if>
function getmicrotime() { list($usec, $sec) = explode(" ",microtime()); return ((float)$usec + (float)$sec); } include('../Beilpuz.php'); $start_time = getmicrotime(); Beilpuz::enableCachingWithKeys($_GET); $template = new BpTemplate('cache range.html'); echo $template->render(); echo '<font size=1>time:' . (getmicrotime() - $start_time).'</font>';
<html> <title><bp:print_title cacheable="true" use="include/check_range"/></title> <body> <h3><bp:value name="number" cacheable="true"/></h3> <bp:check_range cacheable="true" use="include/current_time" > <b>Im in the allowed range of cacheable templates.</b><br> I was created at: <bp:current_time/> </bp:check_range> <hr> Caching is only allowed for numbers between 20 and 40.<br> Please enter a number below, to see if its in the range. <form name="form" method="get"> Enter: <input type="text" name="number" value="<bp:value name="number" cacheable="true"/>" size="5"/> Submit: <input type="submit"/> </form> </body> </html>
function bp_print_title($sig,$template) { $number = intval($_GET['number']); if ($number < 1) $number = 0; $template->setValue('number', $number); return 'Page: ' . $number; } function bp_check_range($sig,$template) { $number = $template->getValue('number'); if ($number >= 20 && $number <= 40) { Beilpuz::allowCacheKey('number'); return $sig->tpl->render(); } }
include('../../Beilpuz.php'); Beilpuz::$templates = '../templates'; Beilpuz::$compiled = '../compiled'; Beilpuz::setDelimiter('{', '}'); $template = new BpTemplate('delimiter.html'); echo $template->render(); function bp_delimiter($sig,$tpl) { $sig->tpl->setValue('delimiter', Beilpuz::$SIG_BEGIN . Beilpuz::$SIG_END . ' / ' . Beilpuz::$SIG_CLOSE.Beilpuz::$SIG_END); return $sig->tpl->render(); }