Skip to content
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

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

Open
TheFox opened this issue Apr 16, 2015 · 14 comments
Open

Comments

@TheFox
Copy link

TheFox commented Apr 16, 2015

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
Copy link
Collaborator

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

@TheFox
Copy link
Author

TheFox commented Apr 16, 2015

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

@barryvdh
Copy link
Collaborator

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

@TheFox
Copy link
Author

TheFox commented Apr 17, 2015

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
Copy link
Collaborator

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

@barryvdh
Copy link
Collaborator

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

@barryvdh
Copy link
Collaborator

Submitted a fix to LaravelCollective: LaravelCollective/html#30

@barryvdh
Copy link
Collaborator

barryvdh commented May 6, 2015

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

@TheFox
Copy link
Author

TheFox commented May 6, 2015

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

  • laravel/framework v5.0.28
  • laravelcollective/html v5.0.4
  • rcrowe/twigbridge v0.7.1

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
Copy link

mayrop commented Jun 18, 2015

I'm getting the same error for Form & HTML

@fox000
Copy link

fox000 commented Aug 27, 2015

Has anyone found a solution how to use Form?

@TheFox
Copy link
Author

TheFox commented Aug 27, 2015

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
Copy link

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
Copy link

RealJTG commented Nov 17, 2015

@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 :(
LaravelCollective/html#41

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

No branches or pull requests

6 participants