Cant output model data on template

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 :

// 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:    **

$viewName = "myHome.latte";
$mymodel = new myModelClass();
$parms = [$mymodel];
$latte = new \Latte\Engine();
$latte->setTempDirectory(__DIR__ . '/../TpltLatte/');
$loader = new myCustomTemplateLoader($cfgprm);
$latte->render($viewName, $parms);

My template:

{block PageTitle}{/block}

My layout:

{layout '@layout.latte'}
{block PageTitle}{$model->getPageTitle()}{/block}
Filip Procházka
Moderator | 4693

I think it should be

$parms = ['model' => $mymodel];

You have to name the parameters that are passed to the template.



Thanks a lot! It works. Cant find it on docs, IMHO should be on home of latte. I wold love find something like this code the first time I found latte, amazing tool. Thanks for all.

3 years ago