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

Using of string resource creates ./template_c directory #45

Open
belka-ew opened this issue May 19, 2015 · 1 comment
Open

Using of string resource creates ./template_c directory #45

belka-ew opened this issue May 19, 2015 · 1 comment

Comments

@belka-ew
Copy link

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.

@belka-ew
Copy link
Author

Ok, I see. There is already such "wrapper": SmartyEngine and I should use the SmartyEngine service instead of Smarty. $this->get('templating.engine.smarty')->getSmarty() should give the expected result.

Another thing about services: Can it be that parameters "smarty.class_file" and "smarty.cache_warmer.class" aren't in use and can be removed from smarty.xml?

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