Reputation: 3141
I have a Helper as the following:
class IconHelper extends Helper{
public function showList(){
//render a template from ctp file
$template = loadFromTemplate('path/to/my.ctp');
}
}
I want a function to render a .ctp template and return it .
Upvotes: 0
Views: 164
Reputation: 3141
I found View Cells
:
In the case that your content can is small inline template, then you can use the Helper, as following:
class IconHelper extends Helper{
public function show($icon){
$template = '<a class="btn btn-default">'.$icon.'</a>';
return $template
}
but in the case when the content is saved in a template CTP file, the best practice is to use the View Cells:
//helper class
class IconListCell extends Cell{
public function display($icon){
//script .....
$this->set(copmat('icon));
}
}
//file: src/Template/Cell/show.ctp
<a class="btn btn-default" style="font-size: 40px;width: 70px;">
<span class="'.$icon.'" id="icon-value-button" data-pack="default">/span>
</a>
Upvotes: 1