Skip to content

Since Symfony 3.0.2, the twig->render method doesn't work with absolute path #17777

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

Closed
Congelli501 opened this issue Feb 12, 2016 · 13 comments
Closed

Comments

@Congelli501
Copy link

Environment:

  • PHP 5.6
  • GNU/Linux
  • Symfony 3.0.2 (ok with 3.0.1)

Since Symfony 3.0.2, the Symfony\Component\Templating\EngineInterface::render method doesn't work with absolute path to the template file (Unable to find template error).

Step to reproduce (from sratch):

# Install a base sf project
wget https://symfony.com/installer
chmod +x installer
./installer new testp
cd testp/

# Use an absolute path to a twig template
cat > src/AppBundle/Controller/DefaultController.php << 'EOF'
<?php

namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;

class DefaultController extends Controller
{
    /**
     * @Route("/", name="homepage")
     */
    public function indexAction(Request $request)
    {
        $absPath = $this->get('kernel')->getRootDir() . '/Resources/views/default/index.html.twig';

        // replace this example code with whatever you need
        return $this->render($absPath, [
            'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..'),
        ]);
    }
}
EOF


# Test with symfony 3.0.2
php bin/console server:run

## Go to http://127.0.0.1:8000 --> Unable to find template "/.../testp/app/Resources/views/default/index.html.twig".

# Switch to symfony 3.0.1
patch -p0 --batch --forward composer.json << 'EOF'
--- composer.json.1 2016-02-12 12:57:16.729074815 +0100
+++ composer.json   2016-02-12 12:57:26.717103221 +0100
@@ -18,7 +18,7 @@
     },
     "require": {
         "php": ">=5.5.9",
-        "symfony/symfony": "3.0.*",
+        "symfony/symfony": "3.0.1",
         "doctrine/orm": "^2.5",
         "doctrine/doctrine-bundle": "^1.6",
         "doctrine/doctrine-cache-bundle": "^1.2",
EOF

composer update

# Test with symfony 3.0.1
## Go to http://127.0.0.1:8000 --> Ok
@xabbuh
Copy link
Member

xabbuh commented Feb 12, 2016

Looks like this is caused by #15272 (see #17683).

Status: Reviewed

ping @jakzal

@jakzal
Copy link
Contributor

jakzal commented Feb 12, 2016

I started looking into this. My problem is there's no clear reference on what kind of paths should be supported by the TemplateNameParser from the FrameworkBundle. Some of the test cases in #15272 are inferred from the existing code (which might be wrong).

re #12894 (comment)

@jakzal
Copy link
Contributor

jakzal commented Feb 15, 2016

I won't be able to look into this before the weekend.

@wesleylancel
Copy link
Contributor

I'm seeing a regression where the latest 2.8.x-dev is no longer able to parse the following snippet, whereas 2.8.2 is. Possibly the same cause?

{% extends "@FOSUserBundle/Resources/views/layout.html.twig" %}

Edit: did some testing, can confirm that this was caused by the changes in #15272. The regular expression changed in that PR did not match @FOSUserBundle/Resources/views/layout.html.twig before, but does after, however, it can't properly parse it.

@xabbuh
Copy link
Member

xabbuh commented Feb 17, 2016

@wesleylancel What error exactly do you experience?

@wesleylancel
Copy link
Contributor

@xabbuh: I'll look up the exact error tomorrow but it says it can't the template in views/@FOSUserBundle or something. Before the PR it simply didn't parse it because the regexp didn't match and it was passed off to Twig, now it does but it can't actually get all the parts correctly so the TemplateReference contains incorrect data.

@francoispluchino
Copy link
Contributor

@wesleylancel The list of affected versions of Symfony is listed in #17683.

@jakzal
Copy link
Contributor

jakzal commented Feb 22, 2016

I'm looking into fixing this now. @wesleylancel I'd appreciate if you shared the stack trace

fabpot added a commit that referenced this issue Mar 3, 2016
…mplate paths (jakzal)

This PR was merged into the 2.3 branch.

Discussion
----------

[FrameworkBundle] Fix a regression in handling absolute template paths

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #17777 #17683
| License       | MIT
| Doc PR        | -

Regression introduced by #15272.

Commits
-------

d8c493f [FrameworkBundle] Fix a regression in handling absolute and namespaced template paths
@fabpot fabpot closed this as completed Mar 3, 2016
@francoispluchino
Copy link
Contributor

@jakzal, @fabpot You close this issue while the PR #17894 is not merged into the 3.0.x branch (and ^2.3). Is it not better to keep this issue open until all the branches be merged?

@jakzal
Copy link
Contributor

jakzal commented Mar 3, 2016

@francoispluchino in our workflow issues are closed as soon as a related PR is merged. There's no need to keep them open. Older branches are merged into newer ones on a regular basis.

@francoispluchino
Copy link
Contributor

@jakzal Ok, thank you for the precisions!

@Babacooll
Copy link

@xabbuh @jakzal I'm sorry to bother you with this, has this been fixed in Symfony 2.8 ? I've seen a release for Symfony 2.3 but not higher. Thanks !

@jakzal
Copy link
Contributor

jakzal commented Mar 16, 2016

Indeed, only Symfony 2.3 was released recently. Don't worry though, 2.7-3.0 will be released soon and will include this fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants