ytake / laravel.smarty Goto Github PK
View Code? Open in Web Editor NEWsmarty template engine for laravel
License: MIT License
smarty template engine for laravel
License: MIT License
(Laravel 5)
The nocache
filter and block tag don't seem to work when including templates. Putting {$smarty.now nocache}
or {nocache}{$smarty.now}{/nocache}
in an included template always outputs the time that the template was first run after being modified. NOTE: the same does not apply when adding the nocache
attribute to the {include}
.
I have caching on and compile_check enabled.
I am not sure why but sessions appear to not work when using Laravel Smarty views.
I got them working again by changing code here https://github.com/ytake/Laravel.Smarty/blob/master/src/Smarty/Engines/SmartyEngine.php#L58
to not use the ob functions.
protected function evaluatePath($path, array $data = [])
{
try {
if (!$this->smarty->isCached($path)) {
foreach ($data as $var => $val) {
$this->smarty->assign($var, $val);
}
}
// render
$cacheId = isset($data['smarty.cache_id']) ? $data['smarty.cache_id'] : null;
$compileId = isset($data['smarty.compile_id']) ? $data['smarty.compile_id'] : null;
return $this->smarty->fetch($path, $cacheId, $compileId);
} catch (\Exception $e) {
$this->handleViewException($e);
}
}
I am not sure what is causing this or why this fixes it.
Dear all,
i like to share my .tpl files between projects with and without Laravel.
My last problem is to access the Laravel-Session-Variables in the template as $smarty.session...
I am aware that i can access it with session() inside the template, but i had to change a lot of templates.
so - my question is: would it be possible to add/change the behaviour of $smarty.session... ?
i found a possible candidate in smarty_internal_compile_private_special_variable.php, but i am not sure if it is the right place :)
kr Tom
Hello, is it possible and how to write my own plugin, which won't be in the default smarty plugin directory inside vendor folder, but samewhere inside app folder? Thanks
Getting error:
Fatal error: Call to undefined method Ytake\LaravelSmarty\Smarty::setTemplateDir() in ProjectDir\vendor\ytake\laravel-smarty\src\SmartyFactory.php on line 203.
"laravel/framework": "5.0.*",
"ytake/laravel-smarty": "^2.1"
Want to render: resources/views/login.tpl
With cmd: \View::make('login')
Since Laravel 9 is now out, could the constraints be updated? ๐๐ป
`Invalid argument supplied for foreach()
at vendor/ytake/laravel-smarty/src/SmartyFactory.php:214
210โ
211โ $smarty->error_reporting = Arr::get($config, 'error_reporting', E_ALL & ~E_NOTICE);
212โ // SmartyTemplate class for laravel
213โ $smarty->template_class = SmartyTemplate::class;
โ 214โ foreach ($config as $key => $value) {
215โ if (in_array($key, $this->configKeys)) {
216โ $smarty->{$key} = $value;
217โ }
218โ }
+21 vendor frames
22 artisan:37
Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))`
Are there plans to support Laravel 8?
notice me don't have function configure in bootstrap/app.php
and the Error: Fatal error: Uncaught Error: Call to undefined method Illuminate\Foundation\Application::configure() in /Users/dk/workspace/SGame/bootstrap/app.php:46 Stack trace: #0 /Users/dk/workspace/SGame/public/admin/index.php(39): require_once() #1 {main} thrown in /Users/dk/workspace/SGame/bootstrap/app.php on line 46
i will get this error: Fatal error: Uncaught ReflectionException: Class config does not exist in /Users/dk/workspace/SGame/vendor/laravel/framework/src/Illuminate/Container/Container.php:803 Stack trace: #0
Hi!
Using Laravel 7.14.1 with Laravel.Smarty 4.0.0.
Changing the 'template_path' variable in ytake-laravel-smarty.php has no effect on loading view files from that path.
I had to change the path from config/view.php for it work. Is this expected behavior?
Same goes for the compile/cache path.
When something else than a Smarty exception is thrown the code enters this line which used a non existing class (at least in my project).
I think in both cases the call to $this->handleViewException($e);
is enough, no?
In Version 6 and 7 there is an issue with assigned template variables in relation with the queue:work command.
Instead of queue:listen queue:work does not always boot Laravel so the existing Smarty Instance is kept.
Result in queue:listen: As expected, the variable gets only applied to the first mailable
Result in queue:work: The variable is dumped in both templates
App/Mail/TestMail1.php
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
class TestMail1 extends Mailable
{
use Queueable;
public function build()
{
$this->view('mail.test', [
'example' => 'assigned to first mailable'
]);
return $this;
}
}
App/Mail/TestMail2.php
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
class TestMail2 extends Mailable
{
use Queueable;
public function build()
{
// "example" is not applied here
$this->view('mail.test');
return $this;
}
}
templates/mail/test.tpl
<pre>{$example}</pre>
TestController.php
Mail::queue(new TestMail1());
Mail::queue(new TestMail2());
Smarty assignments have to be cleared on each Mailable.
In the current implementation, there is a risk that variables that are not overwritten by a second Mailable are erroneously transmitted in an email.
false
true
$variable
is applied to all further mailables (even if the template file name differs)Are there plans to support laravel 7?
Hello,
First I need to say this packge are awesome!
I have a doubt. All times I change a view I need to do
php artisan ytake:smarty-clear-cache
php artisan ytake:smarty-clear-compiled
php artisan ytake:smarty-optimize
Is this right? I really need to do it all times I change my views or have other way to refresh?
I have this simple test file...
<!-- base.tpl -->
{include file='main-nav.tpl'}
Then i have this view composer...
<?php
namespace App\Providers;
use App\Repositories\Eloquent\UsersRepository;
use Illuminate\Support\ServiceProvider;
class ViewComposerServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot(UsersRepository $users)
{
$this->app['view']->composer('main-nav', function ($view) use ($users) {
$view->with('userCount', $users->count());
});
}
/**
* Register the application services.
*
* @return void
*/
public function register()
{
//
}
}
...but it seems that view composer aren't fired for any files that are included like this.
Looking at the output of in Debugbar, the included main-nav.tpl
doesn't get logged as rendered.
Hi there,
I'm trying to update an old project but stucked from 5.8 to 6.0. It tells me that illuminate/view is required but that is replaced by Laravel 6.0.x
- ytake/laravel-smarty 2.5.0 requires illuminate/view 5.5.*|5.6.*|5.7.*|5.8.* -> satisfiable by illuminate/view[v5.5.0, ..., 5.8.x-dev].
- ytake/laravel-smarty 2.4.0 requires illuminate/view 5.5.*|5.6.*|5.7.* -> satisfiable by illuminate/view[v5.5.0, ..., 5.7.x-dev].
- Only one of these can be installed: illuminate/view[v5.5.0, ..., 5.8.x-dev], laravel/framework[v6.0.0, ..., v6.0.4]. laravel/framework replaces illuminate/view and thus cannot coexist with it.
How can I resolve this problem? I thought it is compatible with Laravel 8x as well?
Thanks for any help.
ytake/laravel-smarty 5.0.0 requires php ^7.3 -> your php version (8.0.5) does not satisfy that requirement.
You currently cannot set all smarty config options through the config file.
There should be a way to directly set smarty properties in this file.
https://github.com/ytake/Laravel.Smarty/blob/master/src/Smarty/SmartyFactory.php#L74
My code:
Route::get('/', function () {
\View::assign('word', 'hello');
});
I see that there is a PR for this, could it be reviewed and merged so we can use this pckage with new Laravel version? Thank you in advance @ytake !
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.