交响乐 + HTML5 样板集成?
有没有关于如何将 HTML5Boilerplate 集成到 Symfony 中的示例?我遇到的问题是 Symfony 处理样式表和 javascript 加载的方式。
Symfony 喜欢您将样式表和 javascript 添加到控制器中的特殊对象(或在 view.yml
中定义它们),然后您的模板/视图只需调用 和
。
问题是 HTML5Boilderplate 模板希望您加载 中的
Modernizr.min.js
以及该文件末尾的所有其余 javascript 文件。 。 Symfony 的神奇功能只是想一次性加载它们。我似乎无法找到一种方法来在模板中一次有选择地加载它们。
另外,HTML5Boilerplate 具有 CDN jQuery 加载和动态本地备份加载,如下所示:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.5.1/jqduery.js"></script>
<script>window.jQuery || document.write("<script src='js/backend/libs/jquery-1.5.1.min.js'>\x3C/script>")</script>
是否有办法在 Symfony 模板中完成此操作,而不必将 PHP $_SERVER[whatever]
注入代码中?
我觉得我可以让它们一起工作,但我试图避免让它变得太hacky,因为Symfony使用了很多魔法方法和巫毒......
Symfony版本 我在这个项目中使用 Symfony 1.4。可用的 Web 主机尚未运行 PHP 5.3.x,这是 Symfony 2.0 的要求
Are there any examples out there on how to integrate HTML5Boilerplate into Symfony? The problem that I'm running into is the way Symfony handles stylesheet and javascript loading.
Symfony likes you to add your stylesheets and javascript to a special object in the controller (or define them in the view.yml
) and then your template/view just call <?php include_stylesheets() ?>
and <?php include_javascripts() ?>
.
The problem is that the HTML5Boilderplate template wants you to load the Modernizr.min.js
in the <head>
and all the rest of the javascript files at the end of the </body>
. Symfony's magic function wants to just load them all at once though. And I can't seem to figure out a way to selectively load them one at a time in the template.
Also, HTML5Boilerplate has CDN jQuery loading with a dynamic local backup load like this:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.5.1/jqduery.js"></script>
<script>window.jQuery || document.write("<script src='js/backend/libs/jquery-1.5.1.min.js'>\x3C/script>")</script>
Is there anyway to accomplish this in Symfony templates without having to inject the PHP $_SERVER[whatever]
into the code?
I feel like I can probably make it all work together but I'm trying to avoid making it too hacky because Symfony uses so many magic methods and voodoo...
Symfony Version
I'm using Symfony 1.4 for this project. The available web host isn't running PHP 5.3.x yet, which is a requirement of Symfony 2.0
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您想有选择地加载 Symfony “首选”的 HTML 中不同位置的资源,您将无法使用
load_javascripts()
和load_stylesheets()
。我不熟悉 HTML5Boilerplate,但如果您仍在使用布局文件,为什么不手动将资源包含放在您需要的位置呢?这违背了 Symfony 使用 view.yml 对资源进行排队的方式,但是对于任何框架,迟早你都会遇到需要按照你的方式做一些事情的情况。再说一次,我对 HTML5Boilerplate 并不熟悉,所以如果我没有看到什么,请在评论中告诉我。
If you want to selectively load assets in different locations in the HTML that Symfony 'prefers', you won't be able to use
load_javascripts()
andload_stylesheets()
. I'm not familiar with HTML5Boilerplate, but if you're still using a layout file, why not just manually put the asset includes where you need them to go? This goes against Symfony's way of using view.yml to queue up assets, but sooner or later with any framework you're going to run into cases where you need to do someting your way.Again, I'm not familiar with HTML5Boilerplate, so if I'm not seeing something, let me know in the comments.
如果您使用的是 Symfony 2.0,则应该使用 OryzoneBoilerplateBundle
If you are using Symfony 2.0 you should use OryzoneBoilerplateBundle
您使用什么版本的 symfony?
我使用 html5boilerplate 和 symfony (2.0) 没问题,只需直接从我的资源文件夹中的 twig 模板调用 css 和 javascript 即可。
What version of symfony are you using?
I use html5boilerplate with symfony (2.0) no problem, simply calling the css and javascript straight from a twig template in my resources folder.