PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, August 1, 2022

[FIXED] What is the correct way to add bootstrap to a symfony app?

 August 01, 2022     composer-php, symfony, twig, twitter-bootstrap     No comments   

Issue

I'm using symfony framework 3 to develop a web application. I need to add boostrap's functionality to my application. I installed bootstrap using the below command. (I'm using composer.)

composer require twbs/bootstrap

It installs bootstrap to the application's vendor folder. More specifically vendor\twbs\bootstrap.

I need to attach bootstrap's css and js files in the application's twig templates (located in app\Resources\views) as assets.

e.g.:

<link href="{{ asset('css/bootstrap.css') }}" rel="stylesheet" />

But assets only work with files located in the web (web\bundles\framework) folder. I can copy those .css and .js files from the vendor folder to web folder manually to make this work but there should be a proper way to do it (i.e.: to add assets). e.g.: A command with bin/console?

Any help is appreciated.


Solution

The Symfony Best Practies gives the answer for this Problem: https://symfony.com/doc/current/best_practices.html#web-assets

If you are developing an application like this, you should use the tools that are recommended by the technology, such as Bower and GruntJS. You should develop your frontend application separately from your Symfony backend (even separating the repositories if you want).

In our project we use grunt to build and concat those files into the web-folder.



Answered By - fucethebads
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing