The Slim Framework support forum has moved to http://discourse.slimframework.com. This Tender forum is no longer maintained or monitored.

Basic templating?

Johan's Avatar

Johan

16 Mar, 2014 04:16 PM

I just started with Slim and new to frameworks in general and it has been great creating a small API. But now I need to create the interface and I am stuck on how to organize it. I do NOT want to use a template engine.

I create a directory with views that contain my HTML in this format:

    views
        pages
            dashboard.php
            login.php
        header.php
        footer.php
etc.

Now to render this stuff I put in the route for example /login/
$app->render('pages/login.php');

And I would like the login page to pop up.

Here comes my question... what is the best way to do this? Inside the login.php I need to include the header.php and the footer.php, I can't do it using $app since it complains "Call to a member function render". Should I just use normal PHP includes?

Putting this in the route:

$app->render('header.php');
$app->render('pages/login.php');
$app->render('footer.php');
On every single page does not look elegant to me.

At the same time from the route I want to pass variables for the title of the page and echo the variable in header.php and not in login.php. Should I use controllers here? And pass an array with "title" value etc.?

Tips please, thanks.

  1. Support Staff 1 Posted by Andrew Smith on 20 Mar, 2014 10:13 PM

    Andrew Smith's Avatar

    Just use normal php includes.

    I know you said you dont want to use a template engine but if you want to use a plain PHP template engine take a look at http://platesphp.com/

  2. 2 Posted by Robert on 12 Jun, 2015 07:21 AM

    Robert's Avatar

    @Andrew Smith,

    Can I use smarty as my template engine with slim framework?

    Thank you

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac