有谁知道如何使用Symfony 1.4在模板中添加样式表?
我已经尝试了我能想到的所有方法,从修改前端/config/view.yml到修改模板本身--两者都可以工作。
我从我的搜索中看到,其他人也有同样的问题。在使用include_stylesheets和use_stylesheets之间似乎存在某种冲突--然而,在AFAIK的任何地方都没有记录这一点。
发布于 2010-01-20 17:09:07
编辑:
好了,我想我现在明白了。您应该将include_stylesheets()添加到layout文件的head部分:
<html>
<head>
<title>This is the title</title>
<?php include_stylesheets() ?>
</head>
<body>
<!-- ... -->然后,在模板文件中,使用use_stylesheet()为该模板添加特定的样式表:
<?php use_stylesheet('/path/to/stylesheet.css') ?>从API documentation
include_stylesheets()
打印在view.yml中配置或添加到响应对象的所有样式表的<link>标记。
use_stylesheet()
将样式表添加到响应对象。
Javascript也是如此。
根据API documentation的说法,它应该仍然可以在1.4中工作,sfWebResponse仍然有这个方法:
addStylesheet ( $file,$position,$options) $file样式表文件$position Position $options样式表选项将样式表添加到当前web响应中。
至少这个方法是存在的。
到底是什么问题呢?如果你想调用这个方法,你会得到一个错误吗?或者只是没有添加样式表?
发布于 2010-01-20 15:43:19
http://www.symfony-project.org/tutorial/1_4/en/upgrade#removal_of_the_common_filter
从1.4开始,javascripts和样式表不再自动注入到head标记中。相反,您需要在布局中包含以下内容:
<?php include_javascripts() ?>
<?php include_stylesheets() ?>以防你的文章标题不是拼写错误,你可以使用addStylesheet('...')在响应之外:
$sf_response->addStylesheet('main');发布于 2010-01-20 16:53:23
$sf_context->getResponse()->addStylesheet('style.css')
$sf_context->getResponse()->addJavascript('script.js')
https://stackoverflow.com/questions/2098278
复制相似问题