Ask your Symfony questions! Pay money and get answers fast! (more info)

How do I serve a CSS style sheet dynamically? Symfony

  • SOLVED

Check this out:

[[LINK href="http://www.filemakeremergency.com/page/static/name/new_styles.css"]]http://www.filemakeremergency.com/page/static/name/new_styles.css[[/LINK]]

This is suppose to be a style sheet. So I want the layout to go away. I seem unable to get rid of the layout. This is the code:


public function executeCss($request)
{
if (file_exists($this->userCustomizationPath . 'templates/static' . $request->getParameter('name') . '.php')) {
$fileAsString = file_get_contents($this->userCustomizationPath . 'templates/static' . $request->getParameter('name') . '.php');
} elseif (file_exists(sfConfig::get('sf_root_dir') . '/apps/contest/modules/page/templates/static' . $request->getParameter('name') . '.php')) {
$fileAsString = file_get_contents(sfConfig::get('sf_root_dir') . '/apps/contest/modules/page/templates/static' . $request->getParameter('name') . '.php');
}

if (!$fileAsString) $this->forward404();

$this->setLayout(false);
$this->getResponse()->setContentType('text/css');
$this->fileAsString = $fileAsString;
}



Since setLayout(false) was not working I also tried to creating a blank layout_blank.php and then in view.yml I did this:


all:
layout: layout

howToAskAQuestion2Success:
layout: layout_faq_sidebar

cssSuccess:
layout: layout_blank



But as you can see at that link, the layout is still showing up around the output of the style sheet.

Any thoughts about how to correctly serve the style sheet?

I know this was a bug in Symfony 1.0 but I am using Symfony 1.2.5.


Answers (1)

2010-12-01

Nate Flink answers:

I would try:

$this->getResponse()->setContentType('Content type: text/css');
return $this->renderText($this->fileAsString);


Lawrence Krubner comments:

Okay, now I've got this:

public function executeCss($request)
{
if (file_exists($this->userCustomizationPath . 'templates/static' . $request->getParameter('name') . '.php')) {
$fileAsString = file_get_contents($this->userCustomizationPath . 'templates/static' . $request->getParameter('name') . '.php');
} elseif (file_exists(sfConfig::get('sf_root_dir') . '/apps/contest/modules/page/templates/static' . $request->getParameter('name') . '.php')) {
$fileAsString = file_get_contents(sfConfig::get('sf_root_dir') . '/apps/contest/modules/page/templates/static' . $request->getParameter('name') . '.php');
}

if (!$fileAsString) $this->forward404();

$this->setLayout(false);
// $this->getResponse()->setContentType('text/css');
// $this->fileAsString = $fileAsString;

$this->getResponse()->setContentType('Content type: text/css');
return $this->renderText($this->fileAsString);
}




No change.


Lawrence Krubner comments:

It is showing the wrong layout template. I've set it to show layout_blank.php, which is a completely blank page. I wonder why it shows the wrong layout?


Lawrence Krubner comments:

Finally got it! Thanks.