$sf_response->addStyleSheet() 在 SF 1.4 中不起作用? [英] $sf_response->addStyleSheet() dosen't work in SF 1.4?

查看:26
本文介绍了$sf_response->addStyleSheet() 在 SF 1.4 中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道如何使用 Symfony 1.4 在模板中添加样式表?

我已经尝试了所有我能想到的方法,从修改 frontend/config/view.yml 到修改模板本身 - 两者都有效.

我从我的搜索中看到,其他人也遇到了同样的问题.使用 include_stylesheets 和 use_stylesheets 之间似乎存在各种冲突 - 但是这在 AFAIK 的任何地方都没有记录.

解决方案

好的,我想我现在明白了.您应该将 include_stylesheets() 添加到 layout 文件的 head 部分:

<头><title>这是标题</title><?php include_stylesheets() ?><身体><!-- ... -->

然后在您的 template 文件中,您使用 use_stylesheet() 为该模板添加特定的样式表:

<?php use_stylesheet('/path/to/stylesheet.css') ?>

来自 API 文档:

<块引用>

include_stylesheets()
打印在 view.yml 中配置或添加到响应对象的所有样式表的 标签.

use_stylesheet()
向响应对象添加样式表.

Javascript 也一样.

<小时>

根据 API 文档,它应该仍然可以在 1.4 中工作,sfWebResponse 还有这个方法:

<块引用>

addStylesheet ($file, $position, $options)$file 样式表文件$position 位置$options 样式表选项将样式表添加到当前 Web 响应.

至少方法存在.
究竟是什么问题?如果您想调用该方法,您会收到错误信息还是未添加样式表?

Does anyone know how to add stylesheets in a template with Symfony 1.4 ?

I have tried everything I can think of, from modifying frontend/config/view.yml to modifying the template itself - bothing works.

I have seen from my searches, that other people have had the same problem. There seems to be a clash of sorts between using include_stylesheets and use_stylesheets - however this is not documented anywhere AFAIK.

解决方案

Edit:

Ok I think I got it now. You should add include_stylesheets() into the head section of your layout file:

<html>
   <head>
       <title>This is the title</title>
       <?php include_stylesheets() ?>
   </head>
   <body>
   <!-- ... -->

Then in your template file, you use use_stylesheet() to add a particular stylesheet for this template:

<?php use_stylesheet('/path/to/stylesheet.css') ?>

From the API documentation:

include_stylesheets()
Prints <link> tags for all stylesheets configured in view.yml or added to the response object.

use_stylesheet()
Adds a stylesheet to the response object.

Same for Javascript.


According to the API documentation it should still work in 1.4, sfWebResponse still has this method:

addStylesheet ($file, $position, $options)   
  $file   The stylesheet file  
  $position   Position   
  $options    Stylesheet options  
Adds a stylesheet to the current web response.

At least the method exists.
What exactly is the problem? Do you get an error if you want to call that method or is the stylesheet just not added?

这篇关于$sf_response->addStyleSheet() 在 SF 1.4 中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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