如何“安装"Symfony 上的 Bootstrap Datetimepicker? [英] How to "install" Bootstrap Datetimepicker on Symfony?

查看:35
本文介绍了如何“安装"Symfony 上的 Bootstrap Datetimepicker?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有像 assets/css/bootstrap-4.3.1.cssassets/js/bootstrap-4.3.1.jswebpack 这样的文件.config 我有

I have files like assets/css/bootstrap-4.3.1.css and assets/js/bootstrap-4.3.1.js and in webpack.config I have

.addEntry('js/bootstrap','./assets/js/bootstrap-4.3.1.js')

.addStyleEntry('css/bootstrap', './assets/css/bootstrap-4.3.1.css')

我分别需要 bootstrap-3.3.1.jsbootstrap-3.3.1.css.

我需要在纱线中安装这些,以确保我有 Bootstrap datetimepicker 的先决条件.试过

I need to install these in yarn in order to ensure that I have my perequisites for Bootstrap datetimepicker. Tried with

yarn add bootstrap@3.3.1

没有任何运气.然后我尝试将文件分别手动下载到 assets/css 和 assets/js 中,并再次运行上面的命令,但没有任何运气.所以,我需要使用yarn来改变Bootstrap的版本.然后,我还需要使用 Bootstrap datetimepicker.我怎样才能实现我的目标?与使用纱线相比,此时手动链接 css 和 js 文件对我来说似乎非常重要,但很可能原因只是我对纱线缺乏了解.

without any luck. Then I tried to download the files manually into assets/css and assets/js, respectively and ran the command above again, without any luck. So, I need to use yarn to change the version of Bootstrap. Then, I will need to use Bootstrap datetimepicker as well. How can I achieve my goal? Linking the css and js files manually at this point seems to be extremely for me in comparison to using yarn, but it is highly probable that the cause is just my lack of knowledge about yarn.

编辑

此时我已经

package.json

//...
"depencencies": {
    //...
    "bootstrap": "^3.3.1",
    //...
}
//...

app.js

//...
require("bootstrap");
//...

运行yarn install时的错误信息:

未找到此依赖项:

  • ./assets/js/app.js 中的引导程序

要安装它,您可以运行:npm install --save bootstrap

To install it, you can run: npm install --save bootstrap

推荐答案

过程很简单

  1. 向 formType 字段添加类

  1. Add a class to a formType field

'attr' => ['class' => 'js-datepicker'],

  • 用yarn安装datepicker的JQuery插件

  • Install with yarn the JQuery plugin for datepicker

    yarn add bootstrap-datepicker
    

  • 在 assets/js 中创建一个文件用于 datepicker 配置

  • Create a file in assets/js for datepicker configuration

    在 webpack 中加入 encore 条目

    Add in webpack encore the entry

     .addEntry('datepicker', [
        './assets/js/datepicker.js'
    ])
    

  • 在模板中添加入口链接标签

  • Add entry link tag in template

    {% block stylesheet %}
    {{ encore_entry_link_tags('datepicker') }}
    {% endblock %}
    

  • 在模板中添加入口脚本标签

  • Add entry script tag in template

    {% block javascripts %}
    {{ encore_entry_script_tags('datepicker') }}
    {% endblock %}
    

  • 这篇关于如何“安装"Symfony 上的 Bootstrap Datetimepicker?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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