When rendering a view using Liten’s view object, there are two parameters that can be passed to the display() method.
1 2 3 4 5 6 |
/** * $viewName is the file name minus .php * $data is an array that can be passed and then * manipulated in the view. $app-view-display($viewName, $data = null); |
Contents
Layouts
You can create a layout (template) that other files (children) can extend. The show() method displays a section of content defined by the child view extending it.
1 2 3 4 5 6 7 8 |
<html> <head> <title><?=_h($title);?></title> </head> <body> <?=$show('content');?> </body> </html> |
Views
Create a view that extends the layout and provides content for the show() section in the layout.
1 2 3 4 5 6 7 |
<?php $app = \Liten\Liten::getInstance(); ?> <?php $app->view->extend('_layouts/default'); ?> <?php $app->view->block('content'); ?> <h1>Welcome, <?=_h($name);?></h1> <?php $app->view->stop(); ?> |
Partials
A somewhat alternative to default layouts is partial views which allows you to separate templates for headers and footers.
1 2 3 4 5 6 7 8 |
<?php $app = \Liten\Liten::getInstance(); ?> <?php $app->view->partial('_layouts/header'); ?> <?php $app->view->block('content'); ?> <h1>Welcome, <?=_h($name);?></h1> <?php $app->view->stop(); ?> <?php $app->view->partial('_layouts/footer'); ?> |
Last Modified:
Liten Framework › Forums › View