Welcome Guest, Not a member yet? Register   Sign In
Creating a CI service for using templating engine?
#2

(This post was last modified: 03-22-2018, 03:17 AM by gabpnr. Edit Reason: missing comma )

Hello,

yes, the best way is certainly by creating a service to initliase the Plate class and call his render.

Something like this :

application/Config/Services.php
Code:
// ...
public static function plates(string $view, array $data = null, string $path = '/path/to/template')
{
    $templates = \League\Plates\Engine::create($path);

    return $templates->render($view, $data);
}
// ...

and in any controller action
Code:
$data = [
    'todo_list' => ['Clean House', 'Call Mom', 'Run Errands'],
    'title'     => "My Real Title",
    'heading'   => "My Real Heading"
];

// with the default template
echo \Config\Services::plates('profile', $data);

// or with another template
echo \Config\Services::plates('blogview', $data, '/path/to/template/blog');
Reply


Messages In This Thread
RE: Creating a CI service for using templating engine? - by gabpnr - 03-22-2018, 03:08 AM



Theme © iAndrew 2016 - Forum software by © MyBB