rcrowe / TwigBridge

Give the power of Twig to Laravel
MIT License
895 stars 167 forks source link

Enabling TwigBridge\Extension\Laravel\Html in Laravel 5 to use link_to() #194

Open TheFox opened 9 years ago

TheFox commented 9 years ago

Hi,

how can enable TwigBridge\Extension\Laravel\Html in Laravel 5, TwigBridge 0.7?

In rcrowe/twigbridge/config/twigbridge.php it is disabled by default. As described in 0.7/README.md:

Check out the config/extensions.php file to see a list of defined function / filters. You can also add your own.

But there is no myapp/config/extensions.php. How must this file look like?


I also put the config into my myapp/app/Providers/ConfigServiceProvider.php but it also doesn't work.

For example when I want to use link_to() in my Twig template.

The function "link_to" does not exist

The only way it works is when enabling the extension in rcrowe/twigbridge/config/twigbridge.php.

The README.md says that the link_to() function is added by the default Extensions.


When enabling TwigBridge\Extension\Laravel\Form:

Cannot instantiate Twig extension 'TwigBridge\Extension\Laravel\Form': Unresolvable dependency resolving [Parameter #2 [ $csrfToken ]] in class Collective\Html\FormBuilder

I installed laravelcollective/html as TwigBridge suggest in composer.json. But I would rather put laravelcollective/html into require not suggest. However, this solves not the problem.

barryvdh commented 9 years ago

Perhaps better to remove the extensions and just let people add the function names.

TheFox commented 9 years ago

But link_to() is provided by TwigBridge\Extension\Laravel\Html. How can I use link_to()?

barryvdh commented 9 years ago

Oh eh, I'll need to take a look. Don't use the html/form stuff.

TheFox commented 9 years ago

But why are the HTML functions listed in the README while it's not available in the code? The README says I can use it.

barryvdh commented 9 years ago

Well it was there by default in L4, but removed from L5. It did work but they probably changed the signature sometime.

barryvdh commented 9 years ago

You can also use the HTML and Form facades directly, if you add them to the facades list in the config.

barryvdh commented 9 years ago

Submitted a fix to LaravelCollective: https://github.com/LaravelCollective/html/pull/30

barryvdh commented 9 years ago

Merged and tagged. Does updating laravelcollective/html now work for you?

TheFox commented 9 years ago

No.

Still the same error:

Cannot instantiate Twig extension 'TwigBridge\Extension\Laravel\Form': Unresolvable dependency resolving [Parameter #2 [ $csrfToken ]] in class Collective\Html\FormBuilder

I'm using

I put the config into ConfigServiceProvider.

This is what it looks like:

public function register(){
    config(array(
        'twigbridge' => array(
            'extensions' => array(
                'enabled' => array(
                    'TwigBridge\Extension\Loader\Facades',
                    'TwigBridge\Extension\Loader\Filters',
                    'TwigBridge\Extension\Loader\Functions',
                    'TwigBridge\Extension\Laravel\Auth',
                    'TwigBridge\Extension\Laravel\Config',
                    'TwigBridge\Extension\Laravel\Input',
                    'TwigBridge\Extension\Laravel\Session',
                    'TwigBridge\Extension\Laravel\String',
                    'TwigBridge\Extension\Laravel\Translator',
                    'TwigBridge\Extension\Laravel\Url',

                    'TwigBridge\Extension\Laravel\Form',
                    'TwigBridge\Extension\Laravel\Html',
                ),
                'facades' => array(
                ),
                'functions' => array(
                    'dd',
                ),
            ),
        ),
    ));
}
mayrop commented 9 years ago

I'm getting the same error for Form & HTML

fox000 commented 9 years ago

Has anyone found a solution how to use Form?

TheFox commented 9 years ago

Do you use v0.8? I used v0.7. Maybe the newest version is now working. I don't know, I didn't tried it with v0.8.

jordanlev commented 9 years ago

Not sure if this is the same problem I was having, but I have a pull request which clarifies the README on how to get the Form and Html helpers working for Laravel 5.1

RealJTG commented 9 years ago

@jordanlev I've getting an error with Lumen. Installed laravelcollective/html, enabled service provider and extensions and now I'm getting this error:

InvalidArgumentException in ServiceProvider.php line 236:
Cannot instantiate Twig extension 'TwigBridge\Extension\Laravel\Form': 
Argument 1 passed to Collective\Html\HtmlBuilder::__construct() 
must be an instance of Illuminate\Routing\UrlGenerator, 
instance of Laravel\Lumen\Routing\UrlGenerator given, 
called in \vendor\laravelcollective\html\src\HtmlServiceProvider.php on line 39 

laravel/lumen-framework v5.1.6 laravelcollective/html v5.1.7 rcrowe/twigbridge v0.8.2 twig/extensions v1.3.0

UPD: got it, laravelcollective/html incompatible with Lumen ATM :( https://github.com/LaravelCollective/html/issues/41