How to “install” Bootstrap Datetimepicker on Symfony?

China☆狼群 提交于 2021-01-28 06:40:34

问题


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

and

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

I need bootstrap-3.3.1.js and bootstrap-3.3.1.css, respectively.

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

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.

EDIT

At this point I have

package.json

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

app.js

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

Error message when running yarn install:

This dependency was not found:

  • bootstrap in ./assets/js/app.js

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


回答1:


The process is simple

  1. Add a class to a formType field

    'attr' => ['class' => 'js-datepicker'],
    
  2. Install with yarn the JQuery plugin for datepicker

    yarn add bootstrap-datepicker
    
  3. Create a file in assets/js for datepicker configuration

  4. Add in webpack encore the entry

     .addEntry('datepicker', [
        './assets/js/datepicker.js'
    ])
    
  5. Add entry link tag in template

    {% block stylesheet %}
    {{ encore_entry_link_tags('datepicker') }}
    {% endblock %}
    
  6. Add entry script tag in template

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


来源:https://stackoverflow.com/questions/57385390/how-to-install-bootstrap-datetimepicker-on-symfony

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!