slimphp / Twig-View

Slim Framework view helper built on top of the Twig templating component
http://slimframework.com
MIT License
356 stars 87 forks source link

path_for not working #68

Closed Idreesshahzaib closed 7 years ago

Idreesshahzaib commented 7 years ago

I am getting error Unknown "path_for" function in "/Templates/Partials/index.twig" at line 11. here is index .twig

{% extends "Base.twig" %}

{% block content %}

<header class="main_menu_sec navbar navbar-default navbar-fixed-top">
    <div class="container">
        <div class="row">
            <div class="col-lg-3 col-md-3 col-sm-12">
                <div class="lft_hd">
                    <div class="logo">
                    <a href="{{ path_for('home') }}">Gowarbaam</a>
                    </div>
                </div>
            </div>

here is view in container `$container['View'] = function ($container) { return new \Slim\Views\Twig( DIR . '/../App/Views',[ 'cache' => false //dirname(FILE) . '/../Caching' ]);

 $View->addExtension(new Slim\Views\TwigExtension(
        $container['router'],
        $container['request']->getUri()

    ));
return $View;

};`

geggleto commented 7 years ago

doesn't look like you are adding the extension properly.

1f7 commented 7 years ago

path_for('home') work with named routes with setName f.ex. $app->get('/', 'App\Controllers\Home:index')->setName('home');

geggleto commented 7 years ago

answered.

Cvar1984 commented 4 years ago

path_for('home') work with named routes with setName f.ex. $app->get('/', 'App\Controllers\Home:index')->setName('home');

Im on slim4 is ->setName method from routing got removed? path_for is also not working for me this is my route

$app->any('/home', \App\Controller\HomeController::class)->setName('home');
{{ path_for('home') }}
l0gicgate commented 4 years ago

Im on slim4 is ->setName method from routing got removed?

@Cvar1984 no, it's still here: https://github.com/slimphp/Slim/blob/4.x/Slim/Interfaces/RouteInterface.php#L85

path_for is also not working for me

The functionality has moved to the RouteContext object: http://www.slimframework.com/docs/v4/objects/request.html#obtain-base-path-from-within-route

Cvar1984 commented 4 years ago

Im on slim4 is ->setName method from routing got removed?

@Cvar1984 no, it's still here: https://github.com/slimphp/Slim/blob/4.x/Slim/Interfaces/RouteInterface.php#L85

path_for is also not working for me

The functionality has moved to the RouteContext object: http://www.slimframework.com/docs/v4/objects/request.html#obtain-base-path-from-within-route

I got string(0) "" from

$view = \Slim\Views\Twig::fromRequest($request);
$basePath = \Slim\Routing\RouteContext::fromRequest($request)->getBasePath();

I want to get absolute url for loading assets, i have try using twig-assets too, but it wont't load an images

zamronypj commented 4 years ago

path_for is removed in commit 71d9bb9cc68. Replace with url_for() or full_url_for().