-
Notifications
You must be signed in to change notification settings - Fork 37
Description
If I don't use a file resource but render a template from the string, smarty creates template_c not in the var/cache/prod/smarty/template_c but in the current directory.
Minimal example:
<?php
namespace AppBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class TemplatingResourceTest extends WebTestCase
{
public function testString()
{
$client = static::createClient();
$smarty = $client->getContainer()->get('smarty');
$template = $smarty->fetch('string:{assign var="var1" value="testValue"}{$var1}');
$this->AssertFileNotExists('template_c');
}
}
Running this will fail and will create template_c/ in the symfony root directory. Running similar code from the controller will create template_c/ in the web/ directory (so web/template_c).
What is the problem?
'compile_dir' is set in NoiseLabs\Bundle\SmartyBundle\DependencyInjection\Configuration and it happens in the constructor of NoiseLabs\Bundle\SmartyEngine. So if I call $this->get('smarty') before $this->render(...) in controller I get unconfigured smarty instance.
My suggestion would be to create a smarty service around the \Smarty and set smarty configuration inside of this service. If this solution is acceptable I can create a pull request.