GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • View on GitHub

This view

  • Original page
  • New address

GeezerVison is showing unicframework.github.io — Views

Views

Unic framework support multiple view engine like php, twig etc.

Let’s set the default view directory path:

$app->set('views', __DIR__ . '/views'));

Let’s set the view engine and configuration options:

$app->set('view_engine', 'twig', [
    'cache' => false
]);

Now let’s create a view file index.twig inside the views directory:

<!DOCTYPE html>
<html>
    <head>
        <title></title>
    </head>
    <body>
        
    </body>
</html>

Let’s render a view:

$app->get('/', function($req, $res) {
    $res->render('index.twig');
});

We can pass data to the views:

$app->get('/', function($req, $res) {
    $res->locals->a = 10;
    $res->render('index.twig', [
        'title' => 'Unic',
    ]);
});

The $res->locals variables are by default accessible from views.

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.