0

Problem

I need to generate CSS file while page is rendering (custom colors for each user). In order to achieve that I made an action to render the file and and put the route as a reference, like that:

public function styleAction()
{
    $backgroundColor = $this->getUser()->getCompany()->getBackgroundColor();
    if(!$backgroundColor || $backgroundColor =="")
        $backgroundColor = '#b5dea2';

    $response = new Response();
    $response->setContent($this->render('*WHAT_TO_PUT_HERE*:style.css.twig',array('backgroundColor' => $backgroundColor)));
    $response->headers->set('Content-Type', 'text/css');
    return $response;
}

Route:

css_route:
    path: /css/mainStyle
    defaults: { _controller: AcmeMainBundle:Default:style }

Question: What to write in place of "WHAT_TO_PUT_HERE" in order to access to the file located under /web/css/style.css.twig.

1
  • 1
    same as other twig redered by a controller (no difference in this case) so Resources\views\Default\style.css.twig. Hope this help Commented Jan 25, 2015 at 14:36

1 Answer 1

1

Put the file in your Bundles Resources\views directory.

Sign up to request clarification or add additional context in comments.

2 Comments

Yeah but this not an appropriate way to do it. Is there any chance to access them without moving the files?
That's is the best practice way. All resources should live in bundles. templates and public js and css files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.