Skip to content

Using of string resource creates ./template_c directory #45

@belka-ew

Description

@belka-ew

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions