php - Instantiating twig in a namespaced class -



php - Instantiating twig in a namespaced class -

i'm running issues trying figure out how utilize twig in specific way. i'm trying write view class can utilize in application regardless of template scheme installed, way things have alter templates , view class.

however, when seek , create twig objects in class, fatal error: class 'template\twig_loader_filesystem' not found errors, , i'm not sure i'm missing.

can point me in right direction?

here's i've got far...

composer.json

{ "name": "movies", "description": "find movies", "require": { "ext-curl": "*", "twig/twig": "~1.0" }, "autoload": { "classmap": [ "app/classes" ] } }

index.php

require_once 'app/app.php'; utilize template\template; echo template::render('hello.html', array('name' => 'bob', 'age' => '33'));

app/app.php

define('app_directory', __dir__ . '/..'); require_once app_directory . '/vendor/autoload.php';

app/classes/template.class.php

namespace template; class template { static function render($template_name, $template_data = array()) { $loader = new twig_loader_filesystem(app_directory . '/app/templates'); $twig = new twig_environment($loader); homecoming $twig->render('hello.html', array('name' => 'lisa', 'age' => '33')); } }

ok, turned out whenever seek , include twig namespaces on template class, doing wrong. looking @ other projects organization has set together, turns out adding

use twig_environment; utilize twig_loader_filesystem;

to class enough. wasn't sure if had add together anything, since autoloader included, or if had include part of path, twig_twig/loader/filesystem or that. neither of working.

php namespaces twig

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -