view([filename], array $data);
Then inside [filename]
you have helper functions $block(key, [default])
, $start(key)
, and $end()
. In addition, you can include a parent view using $extends = [parentview];
.
Values and blocks from a child view will overwrite the values defined in a parent view (or grandparent view, etc..) allowing you to safely inherit things like a page title from multiple nested children. Suppose you view('post')
and it inherited from post
which in turn inherited from layout
:
Layout: <?= $block('page_title', 'Welcome!'); ?>
Page.php: <?php $page_title = 'Article Title'; ?>
Post.php <?php $page_title = $post->title; ?>
The result would be $post->title
and not "Article Title" or "Welcome!" dispite the fact they were defined in the parent views.
As much as I've tried, I cannot nest a partial and pass additional data to is, such as on line 10 of view.php .
Does the passed data need to be in a set array format?
In my case there is a variable
$settings
set on the index page.This is passed to the view function,
The home.php template file references the passed
$settings
variable, but then nothing happensI created a small test project, adding an index file, that calls the view function.
https://github.com/onebitrocket/php-ti