My sample widget:
class myWidget extends sfWidgetFormTextarea{
public function getJavascripts(){
return array('my_widget.js');
}
public function getStylesheets(){
return array('my_widget.css');
}
}
Form template:
<?php include_javascripts_for_form($form) ?>
<?php include_stylesheets_for_form($form) ?>
<?php echo $form;?>
The problem is that those 2 functions produce link and script tags right before rendering form.
How can I move them to the head section?
Try adding the .css and .js to your module’s view.yml instead of in the template:
That will get parsed and dumped into your head tag.
If you have access to the current context’s response you can call addJavascript or addStylesheet on the response to inject them into the head. From an action:
From a template: