将 jQuery 包含到 Symfony2 中 [英] Include jQuery into Symfony2

查看:28
本文介绍了将 jQuery 包含到 Symfony2 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Symfony2 框架的新手,并不完全了解如何使用 javascript 以及如何以最佳方式包含它们.

I am new in Symfony2 framework and not fully understand how to work with javascripts and how to include theirs in the best way.

我需要的是:在每个页面中包含 jQuery 脚本.

What I need: to include jQuery script to each page.

我所拥有的:我有这样的常见布局:

What I have: I have common layout like this:

<!DOCTYPE html>
<html>
    <head>
        {% block javascripts %}{% endblock %}
    </head>
    <body>
        {% block body %}{% endblock %}

    </body>
</html>

jquery.js 应该放在哪里.web/bundles/jquery 怎么样?或者有一些特殊的官方jquery包?我应该使用 asset() 以及如何使用?

Where jquery.js should be placed. What about web/bundles/jquery? Or there are some special official jquery bundles? Should I use asset() and how?

推荐答案

假设你的 jquery.min.js 放在src/Acme/FooBundle/Resources/public/js/

Assuming your jquery.min.js is placed under src/Acme/FooBundle/Resources/public/js/

你可以使用任何一个

<script type="text/javascript" src="{{ asset('bundles/acmefoo/js/jquery.min.js') }}"></script>

{% javascripts
    '@AcmeFooBundle/Resources/public/js/jquery.min.js'
%}
    <script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}

进入你的树枝模板.

确保您之后安装了资产或运行此命令

Make sure you installed the assets afterwards or run this command

php app/console assets:install web --symlink

这篇关于将 jQuery 包含到 Symfony2 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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