Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should components add JavaScript and CSS in Symfony

My layout.php calls include_javascripts() before my componet could call sfResponse::addJavascript(). Is there a "helper" or a "best practice" to handle this?

Do I have to Seperate the call sfResponse::addJavascript()? I were happy to avoid it.

Here ist my actual workaround:

<head>
  <?php $nav = get_component('nav', 'nav') /* Please show me a better way. */ ?>
  <?php include_javascripts() ?>
  ...
</head>
<body>
  <?php /* include_component('nav', 'nav') */ ?>
  <?php echo $nav ?>
  ...
</body>

Thanks

like image 744
koalabruder Avatar asked Dec 10 '22 17:12

koalabruder


1 Answers

From: http://www.symfony-project.org/book/1_2/07-Inside-the-View-Layer

File Inclusion Configuration

// In the view.yml

indexSuccess:
  stylesheets: [mystyle1, mystyle2]
  javascripts: [myscript]

// In the action

$this->getResponse()->addStylesheet('mystyle1'); 
$this->getResponse()->addStylesheet('mystyle2'); 
$this->getResponse()->addJavascript('myscript');

// In the Template

<?php use_stylesheet('mystyle1') ?>
<?php use_stylesheet('mystyle2') ?>
<?php use_javascript('myscript') ?>
like image 174
Tom Avatar answered Dec 27 '22 14:12

Tom