如何在 Symfony 2 yml 或 xml 配置文件中定义 Assetic 资源? [英] How to define Assetic resources in Symfony 2 yml or xml configuration file?

查看:21
本文介绍了如何在 Symfony 2 yml 或 xml 配置文件中定义 Assetic 资源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你能在配置文件(yml/xml)中定义资产资源吗?

Can you define assetic resource in configuration file (yml/xml)?

让我们以 jquery 为例.我想要这样的配置:

Lets take jquery as example. I would like to have configuration like this:

# app/config/config.yml
assetic:
  resources:
     jquery: 
        latest: "app/Resources/js/jquery-1.6.2.js"
        1_6_2: "app/Resources/js/jquery-1.6.2.js"
        1_5: "app/Resources/js/jquery-1.5.js"

并且能够从我的应用程序中的任何模板访问此资源,如下所示:

And to be able to access this resource from any template in my application something like this:

{% javascripts 'jquery.latest' %}
<script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}

这样做的正确方法是什么?

What is a proper way to do this?

还有一件事.如何在 twig 模板中引用路径 app/Resources/js/jquery-1.6.2.js?

And another thing. How do I reference path app/Resources/js/jquery-1.6.2.js in twig template?

{% javascripts 'app/Resources/js/jquery-1.6.2.js' %}
<script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}

这不起作用.你能做到这一点吗?我可以在 app/Resources 中放置哪些资源以及如何在我的模板中访问它们?记录在哪里?

This does not work. Can you do this at all? What resources I can place in app/Resources and how do I access them in my templates? Where it is documented?

现在 Symfony 2 确实缺乏文档......

Right now Symfony 2 is really lacking in documentation...

推荐答案

在你的 app/Resources 文件夹中定义资源的路径必须以尾随定义:../"

The path to define resources in your app/Resources folder must defined with a trailing: "../"

{% javascripts 
  "../app/Resources/js/qtip.jquery.js"
  "../app/Resources/js/layout.js"
  "@HomeBundle/Resources/js/*"  
%}

虽然不完全确定如何帮助您解决第一个问题,但希望这能有所帮助.

Not entirely sure how to help you on your first question, though, but hopefully this can help.

这篇关于如何在 Symfony 2 yml 或 xml 配置文件中定义 Assetic 资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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