Can someone tell me how can I use https://github.com/slimphp/PHP-View/ for my templates in slim framework (no twig or smarty) and use a layout php file or a header/footer file and render subviews?
1 Like
Hello @AhmadKarim
The Slim PHP-View library uses plain PHP code to render templates.
I think the most common way of merging header/body/footer files is by using the include and require statement.
<?php
require __DIR__ . '/header.html.php';
require __DIR__ . '/about.html.php';
require __DIR__ . '/footer.html.php';
Hello, I am very new to slim but I am learning it.
I have same question because I am not sure if I do that in the right way. So far I made a layout which includes css styles and javascripts and so and used setLayout.
The template structure looks like so:
In the routes.php (which was created when I used the composer) I just made attributes
$renderer->addAttribute("footer", "footer.html");
$renderer->addAttribute("header", "header.html");
In the layout.html I made this code part
Is this the right way (or one of the ways which is ok) or are there better solutions (if I am missing some features)?