Cant output model data on template
Notice: This thread is very old.
- jkeod
- Member | 2
What im doing wrong ?
I having problems to output model data on template, the model class is set, has
the method and the method returns non empty string.
When i put literal inside my template instead of {$model->getPageTitle()} it
works fine.
Im trying to follow the example when code refer variable directly like that:
<p>{$item}</p>
The way i coded dont make latte find the object and throw the following
error:
Call to a member function getPageTitle() on null
The generated code is :
<?php
// prolog Latte\Macros\BlockMacros
//
// block PageTitle
//
if (!function_exists($_b->blocks['PageTitle'][] = '_lb3a1c833a31_PageTitle')) { function _lb3a1c833a31_PageTitle($_b, $_args) { foreach ($_args as $__k => $__v) $$__k = $__v
;echo Latte\Runtime\Filters::escapeHtml($model->getPageTitle(), ENT_NOQUOTES) ;
}}
?>
**My source code is:**
**My controller: **
<?php
$viewName = "myHome.latte";
$mymodel = new myModelClass();
$parms = [$mymodel];
$latte = new \Latte\Engine();
$latte->setTempDirectory(__DIR__ . '/../TpltLatte/');
$loader = new myCustomTemplateLoader($cfgprm);
$latte->setLoader($loader);
$latte->render($viewName, $parms);
?>
My template:
<?php
{block PageTitle}{/block}
?>
My layout:
<?php
{layout '@layout.latte'}
{block PageTitle}{$model->getPageTitle()}{/block}
?>
- Filip Procházka
- Moderator | 4668
I think it should be
$parms = ['model' => $mymodel];
You have to name the parameters that are passed to the template.