将引导程序添加到 symfony 应用程序的正确方法是什么? [英] What is the correct way to add bootstrap to a symfony app?

查看:22
本文介绍了将引导程序添加到 symfony 应用程序的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 symfony 框架 3 来开发 Web 应用程序.我需要将 boostrap 的功能添加到我的应用程序中.我使用以下命令安装了引导程序.(我正在使用作曲家.)

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

它将引导程序安装到应用程序的供应商文件夹.更具体地说是 vendor wbsootstrap.

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

我需要将引导程序的 cssjs 文件附加到应用程序的 twig 模板(位于 appResourcesviews 中)作为资产.

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

例如:

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

但资产仅适用于位于 web (webundlesframework) 文件夹中的文件.我可以手动将这些 .css.js 文件从供应商文件夹复制到 web 文件夹以使其工作,但应该有一个正确的方法来做到这一点(即:添加资产).例如:带有 bin/console 的命令?

But assets only work with files located in the web (webundlesframework) 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?

感谢任何帮助.

推荐答案

Symfony Best Practies 给出了这个问题的答案:https://symfony.com/doc/current/best_practices.html#web-assets

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

如果您正在开发这样的应用程序,您应该使用技术推荐的工具,例如 Bower 和 GruntJS.您应该将前端应用程序与 Symfony 后端分开开发(如果您愿意,甚至可以将存储库分开).

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).

在我们的项目中,我们使用 grunt 构建这些文件并将其合并到 web 文件夹中.

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

这篇关于将引导程序添加到 symfony 应用程序的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆