I have the following function that loads a template from a file:
public function renderText($text, $data=[], $return=false) {
$template = $this->smarty->createTemplate('string: '.$text, null, null, $data);
if($return)
return $template->fetch();
else
$template->display();
}
And I load the template with the needed variables using
$this->renderText(Yii::app()->smarty->renderText($object->readData(), ['contract'=>$contract], true));
This works perfect for my situation. However, I need to extend this function, so that I can load another template inside this template from memory. Something like {{include}}
function but the one that's specific for my application and is loaded from memory. So far I have this function include_content
:
$template = Object::model()->findByAttributes(['name'=>$params['template']]);
echo $template->readData();
But this doesn't read the variables, just prints them like a string: So if I have two templates:
Main: {{include_content template="SomeBody"}}
SomeBody: {{$contract->id}}
If I open "Main", I need it to print the contract id, not the string "{{$contract->id}}",
I have tried using the renderText function again, but that function doesn't add the parent template's variables in it. What can I do to achieve that?
Thank you,