8000 Since Symfony 3.0.2, the twig->render method doesn't work with absolute path · Issue #17777 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
Since Symfony 3.0.2, the twig->render method doesn't work with absolute path #17777
Closed
@Congelli501

Description

@Congelli501

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0