Disable CSS stylesheet for a specific action in Symfony

我的梦境 提交于 2019-11-30 04:46:58

问题


Is there any way of disabling a stylesheet in view.yml for a specific action in Symfony?

For example I've got this in my view.yml:

default:
  stylesheets:    [default.css]

I want to be able to do something like:

displaySuccess:
  stylesheet: [!default.css]

to disable default.css in displaySuccess only

Is this possible or do I have to explicitly say which modules/actions should have default.css?


回答1:


You can remove or add stylesheets to a modules view.yml by doing the following:

displaySuccess:
  stylesheet: [-default]

would remove default.css from the display action. Simply putting

displaySuccess:
  stylesheet: [-*]

would remove all stylesheets.




回答2:


to remove for example, unecessary /sfDoctrinePlugin/css/default.css, now you can overwrite the backend styles with your own!

maybe put it into yout layout.php:

<?php sfContext::getInstance()->getResponse()->removeStylesheet('/sfDoctrinePlugin/css/global.css'); ?>

<?php sfContext::getInstance()->getResponse()->removeStylesheet('/sfDoctrinePlugin/css/default.css'); ?>



回答3:


I'm not 100% certain, but I believe the compiled view.yml file is processed before execution of the action. If that's true, you can do:

public function executeDisplay()
{
  $this->response->removeStylesheet('default.css');
}

I find view.yml to be a little inflexible. You may find it easier to have a global "head" template that gets included in your layout(s). Then you can check sfConfig values to see if you should include individual files, making it easier to turn them on and off.



来源:https://stackoverflow.com/questions/4325789/disable-css-stylesheet-for-a-specific-action-in-symfony

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!