Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Template engine as service? #7

Closed
URSELF-FR opened this issue Feb 8, 2018 · 1 comment
Closed

Use Template engine as service? #7

URSELF-FR opened this issue Feb 8, 2018 · 1 comment

Comments

@URSELF-FR
Copy link

Hi,

Thanks for your amazing router, I use it in my project and it's really good!
But I am using Twig templating and I was thinking of a way to incorporate it to your router? Is there any way to add it as a service or something like this and in this way I could render my view in my controller?

Thanks for your work.

@miladrahimi
Copy link
Owner

miladrahimi commented Feb 9, 2018

Why don't you return Twig response in your route or controller simply?

require "vendor/autoload.php";

$router = new \MiladRahimi\PHPRouter\Router();

$router->get('/', function () {
    $loader = new Twig_Loader_Filesystem('/path/to/themes');
    $twig = new Twig_Environment($loader);

    return $twig->render('theme.html');
});

$router->dispatch();

You are free to use any kind of architecture for your project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant