2

My experience with Symfony frontend development is definitely limited. According to http://symfony.com/blog/new-in-symfony-2-6-bootstrap-form-theme I read that adding bootstrap_3_layout.html.twig as a twig form resource I should be able to essentially add Bootstrap themes to my form.

I presume I need to add some CSS files somewhere, maybe, but I haven't even got that far yet.

My problem is that after setting the reference as per the blog post:

# Twig Configuration
twig:
    debug:            "%kernel.debug%"
    strict_variables: "%kernel.debug%"
    form:
        resources: ["bootstrap_3_layout.html.twig"]

in my config.yml file, I get the following "error stack" in Symfony:

[3/3] Twig_Error_Loader: Unable to find template "bootstrap_3_layout.html.twig" in kernel.root_dir/Resources/views/base.html.twig at line 10.
[2/3] InvalidArgumentException: Unable to find template "bootstrap_3_layout.html.twig" : "The file "bootstrap_3_layout.html.twig" does not exist (in: /path-to-symfony/app/Resources).
[1/3] InvalidArgumentException: The file "bootstrap_3_layout.html.twig" does not exist (in: /path-to-symfony/app/Resources).

I added twig-bridge via composer, just in case, but that doesn't seem to resolve it.

The only location of a file with that name that I can find is at: ./vendor/symfony/symfony/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_3_layout.html.twig.

If I put a breakpoint in the vendor/twig/twig/lib/Twig/Loader/Filesystem.php file in the findTemplate method, a normal page goes through the process of iterating over $this->paths['__main__'] which has two entries:

  • path-to-symfony/app/Resources/views
  • path-to-symfony/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Resources/views/Form

I'm guessing that I need to somehow put the directory that the file is in into that paths array, but don't know how.

Can anyone point me in the direction of this (no doubt) simple solution?

Many thanks.

3
  • Can you please show us the part of Twig where you are trying to use Bootstrap theme? I am currently working on a project that uses Bootstrap and I can tell that, apart from regular Bootstrap's CSS file, it does not require any other... Commented May 23, 2015 at 22:40
  • @JovanPerovic: ATM I'm not actually trying to use it at all... just trying to get Symfony to recognise that I can use it (I think?) Either way, I've added the entry from my config.yml file if that helps? Commented May 23, 2015 at 23:02
  • I added the answer that might be helpful to you. Let me know if that worked... Commented May 24, 2015 at 0:35

1 Answer 1

1

Ok, the thing is that by defining twig > form > resources, you're telling Symfony2 that you will have a custom resource located within your ./app/Resources directory.

To resolve this, just copy/paste the file ./vendor/symfony/symfony/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_3_layout.html.twig to ./app/Resources and it should work.

Optionally, you could apply the theme to a each form individually, without touching config.yml. I do it that way, because I like to have a complete control over which form gets rendered how.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I guess I can do this if I need to, but I added some additional details to my original question regarding trying to add the new path to the $this->paths['main'] array somehow? That to me seems more 'correct' but I really have no idea at this point.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.