slimphp / slim-views Goto Github PK
View Code? Open in Web Editor NEWSlim Framework 2 custom views
Slim Framework 2 custom views
What about require in composer.json
something like slim/slim-views-implementation and make specific packages for each template system (including Plates, as suggested in a PR) matching this requirement via
providefeature of Composer? Exactly like
psr/log-implementation` works.
I am using siteUrl
in Smarty templates on an HTTPS website and it generates HTTP URLs. It should generate HTTPS URLs.
Can you add support for setting multiple templares dirs? Twig already support it, why don't add it to this lib?
Simply edit in Slim\Views\Twig:
/**
* DEPRECATION WARNING! This method will be removed in the next major point release
*
* Get a list of template directories
*
* Returns an array of templates defined by self::$twigTemplateDirs, falls
* back to Slim\View's built-in getTemplatesDirectory method.
*
* @return array
**/
private function getTemplateDirs()
{
if (empty($this->twigTemplateDirs)) {
return $this->getTemplatesDirectory();
}
return $this->twigTemplateDirs;
}
/**
* Sets an array of paths where to look for templates.
* @param string|array $directory
*/
public function setTemplatesDirectory($directory)
{
$this->templatesDirectory = $directory;
}
Setting templates.path in the Slim configuration options doesn't set the path for the Twig view. This creates exceptions like:
Uncaught exception 'Twig_Error_Loader' with message 'The "" directory does not exist.
It should at least be documented that $view->setTemplatesDirectory(PATH_TO_DIRECTORY)
needs to be called for this to work
Type: Twig_Error_Syntax
Message: The function "urlFor" does not exist in "views/base.html.twig" at line 28
this is what i get when i try to use all thre functions.
my composer.json:
{
"require" : {
"slim/slim" : "2.*",
"doctrine/orm" : "2.4.*@dev",
"slim/views" : "0.1.*",
"twig/twig" : "1.*"
}
}
I'm a little confused. If I want to use Mustache, would you accept a pull request to this repo or should I use the deprecated repo or am I supposed to use this, fork, write my own and not contribute back?
I saw that you wanted it to be smaller, but wasn't clear if others wanted to use a different templating engine.
Thanks again!!
Hi.
I have a problem.
Why does not it work redirect?
$app = new \Slim\App();
$app->get('/', function ($request, $response, $args) {
return $response->withRedirect($this->router->pathFor('name'));//not work
});
$app->get('/auth/signup', function ($request, $response, $args) {
return 'Hello';
})->setName('name');
$app -> run();
or
$app->get('/', function ($req, $res, $args) {
return $res->withStatus(302)->withHeader('Location', '/auth/signup'); //Not work
});
Thanks!,
My apologies if this is already a feature .. I couldn't find it documented anywhere.
It'd be really handy if Slim could support multiple view types in the same application. My particular use case is:
I want user-facing views to be rendered as Twig templates, since it makes sense to use a specialised HTML-rendering template engine for that. However, I also generate files from data passed to the system (in my case a particular type of tab-delimited file), but could equally be CSV, XLS, PDF, ... whatever
I can do this by simply spitting out stuff that I want, but it'd be really nice to be able to have a 'view' so that the template file in question could be edited by people who are experts in genomics, but perhaps not in web development
Thanks ๐
Hi,
I'm trying to get started with Slim Views and Smarty.
I have downloaded Smarty 3.1.x and extracted the libs dir to /var/www/my_site/vendor/smarty.
I have following initialization in my index.php for slim:
<?php
require 'vendor/autoload.php';
require 'app-config.php';
require 'hrcapi-util.php';
$app = new \Slim\Slim(array(
'log.writer' => new \Slim\Extras\Log\DateTimeFileWriter(),
'view' => new \Slim\Views\Smarty()
));
$view = $app->view();
$view->parserDirectory = '/var/www/my_site/vendor/smarty';
$view->parserCompileDirectory = dirname(__FILE__) . '/compiled';
$view->parserCacheDirectory = dirname(__FILE__) . '/cache';
$view->parserTemplatesDirectory = dirname(__FILE__) . 'templates';
$view->parserExtensions = array(
dirname(__FILE__) . '/vendor/slim/views/Slim/Views/SmartyPlugins',
);
When I invoke a route, with a template call as so;
$app->get('/api/members/unsubscribe/:memberid', function ($memberid) use ($app) {
$app->render('unsubscribe.tpl', array('result' => 'OK'));
});
I get a blank page and an error in my web server log:
[Wed Aug 28 13:45:07 2013] [error] [client 127.0.0.1] PHP Fatal error: Call to undefined method Slim\\Views\\Smarty::all() in /var/www/my_site/vendor/slim/views/Slim/Views/Smarty.php on line 87
Any ideas?
how to use {{ dump(var) }} with twig? since the last update v1.1.0 Twig extension, Debug is become impaired, what to do? :(
twigphp/Twig-extensions@c0ab818
index.php (Bootstrap)
<?php
define('ROOT', dirname(__DIR__));
# Autoload
$loader = require ROOT.'/vendor/autoload.php';
// $loader->add('Lib', ROOT.'/lib/');
// spl_autoload_register(function($class){
// $list = [
// ROOT.'/app/'.$class.'.php',
// ROOT.'/lib/'.$class.'.php',
// ROOT.'/lib/'.$class.'.class.php',
// ];
// foreach($list as $k => $v){if(file_exists($v)){
// include $v; return true;
// }}
// });
# Init Slim
$app = new \SlimController\Slim([
'mode' => 'production',
'debug' => false,
'view' => new \Slim\Views\Twig(),
'templates.path' => ROOT.'/templates',
'cacheDirectory' => ROOT.'/cache',
'controller.class_prefix' => '\\MyApp\\Controller',
'controller.method_suffix' => 'Action',
'controller.template_suffix' => 'html.twig'
]);
# Gestion de la configuration selon le mode
if(\Lib\Func::env() == 'LOCAL') $app->config('mode', 'development');
$app->configureMode('production', function() use ($app){
$app->view->parserOptions = ['cache' => $app->config('cacheDirectory')];
$app->view->parserExtensions = [
new \Slim\Views\TwigExtension()
];
});
$app->configureMode('development', function() use ($app){
$app->config([
'debug' => true
]);
$app->view->parserOptions = ['debug' => true];
$app->view->parserExtensions = [
new \Slim\Views\TwigExtension(),
new \Twig_Extensions_Extension_Debug()
];
});
# Components
$app->addRoutes([
'/' => 'Home:index',
]);
// require_once ROOT.'/app/routes.php';
$app->run();
Is it not possible to have multiple template directories?
$view->setTemplatesDirectory($dir);
seems to only accept one directory, as does the config. The $twigTemplateDirs will be deprecated it says, so I am not using that :)
Maybe I'm missing something, but I don't see a way in the docs to do $twig->addExtension()
After upgrading a project to slim-views from extras, I'm not able to use Twig's dump function because of this
Is this functionality in the pipeline, or is it already there and I just need more coffee?
Hello
I use your code with the Twig view.
When I write:
$this->app->render(); $this->app->log->debug('Writing a log message after page rendering.');
I could read the log message in the debug bar, while if I don't use your code, but the raw DebugBar code, the message is never showed.
Why ?
Thank you in advance
Andrea
When try to load Twig Extension as indicated in the manual, I get this error
Fatal error: Class 'Twig_Extension' not found.
I think it is the Parent class of TwigExtension that is the problem.
Is there a way to set smarty options like "setCaching" or else?
What's the difference between baseUrl() and currentUrl() ?
If I'm on the page http://www.iubar.it/index.php
, how can I get the address http://www.iubar.it
(wihout the page name) ???
Thank you in advance for any help
Regards
Andrea
I'm getting the following exception:
Strict Standards: Declaration of Slim\Views\Twig::render() should be compatible with that of Slim\View::render()
I cleared it up by adding $data=null as a parameter to Slim\Views\Twig::render() even though the extra argument doesn't seem to be useful.
Hello,
I will wish to also incorporate Assetic to manage resources. Do you know how to integrate?
Thank you
Hi
I need to set the TwigEnviroment (or better the TraceableTwigEnvironment) in Slim.
I'm trying to integrate your project with the DebugBar project.
Any advice ?
Regards
Andrea
the new version you get with composer require twig/twig changes he way autoloader works and deletes some classes so this slim views don't work any more with it.
Slim-Views calls "$this->all()" method in Twig.php:88, which is not provided in Slim only since 2.3.0
git diff:
diff --git a/composer.json b/composer.json
index ad88722..14b8286 100644
--- a/composer.json
+++ b/composer.json
@@ -18,7 +18,7 @@
}
],
"require": {
"slim/slim": ">=2.2.0",
"slim/slim": ">=2.3.0",
"php": ">=5.3.0"
This has worked with the Smarty view from the Slim-Extras repository. Unfortunately the the usage of the data attribute has changed, and the View does no longer work with the current version of Slim.
Hi I'm trying to use the dump function in a twig template but I get a "The function "dump" does not exist" error. I have the following parser options:
'charset' => 'utf-8',
'auto_reload' => true,
'strict_variables' => false,
'autoescape' => true,
'debug'=>true
Any suggestions would be greatfully recieved.
Isn't it that you have to require smarty or twig to use them?
This should be added to the example composer.json in the readme.
Hello,
I've a problem with Twig Extension :
require 'vendor/autoload.php';
$app = new \Slim\Slim(array(
'debug' => true,
'templates.path' => 'views/',
'view' => new \Slim\Views\Twig(),
));
$view = $app->view();
$view->parserOptions = array(
'debug' => true,
);
$view->parserExtensions = array(
new \Slim\Views\TwigExtension()
);
$app->get('/hello/:name', function ($name) use ($app) {
$app->render('hello.html.twig', array(
'name' => $name,
));
});
$app->run();
And the error : Fatal error: Class 'Twig_Extension' not found in ***\vendor\slim\views\TwigExtension.php on line 38
Have you any ideas ?
Thanks
Are there plans to make SlimViews compatible with Slim 3.0?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.