How to link to a page in Twig

Hi
I have a twig project with the following index.php:

<?php
require_once 'vendor/autoload.php';
include 'dist.php';

$loader = new Twig_Loader_Filesystem('templates');
$twig = new Twig_Environment($loader);



$loader->addPath('displays');
$twig->addGlobal('css', $css);
$twig->addGlobal('js', $js);


if (basename($_SERVER['REQUEST_URI']) == '1') {
echo $twig->render('Local History/index.twig');
}


if (basename($_SERVER['REQUEST_URI']) == '2') {
    echo $twig->render('Local History/V1 Flying Bomb/page1.twig');
}



?> 

Currently I’m using reading the URL to see which page should be rendered as something like href="Local History/V1 Flying Bomb/page1.twig" does not work.
Is there a proper way to do this in twig?
I tried installing Symfony and following the doc http://symfony.com/doc/current/templating/render_without_controller.html
but I get Fatal error: Uncaught Twig_Error_Syntax: Unknown "render" function
Any ideas?

Didn’t get what exactly you are trying to say but in Symfony we can create templates in views folder and call them like:

  return $this->render('default/index.html.twig', array());

But your project is not looking symfony based but twig. So in twig you can follow this guide http://twig.sensiolabs.org/doc/2.x/api.html

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.