Reputation: 2023
I am creating a extension for the Magento 1.7.0.2 platform. I have been successful so far as the extension is used to basically load jquery & js which is managed in the admin panel.
The problem is there are multiple yes/no configurations (in the admin settings using storeConfig) and I wish not to load via .phtml using echo if, else etc..as these would not be available for merging/compression if requested via another compression extension (aka fooman of default magento) as they are static .phtml files. (PS also would having a rather large, multiple echo if, echo else file be slower than xml?)
So I want to load these files via layout...but not using the .xml layout procedure under design/default/default/layout as there are too many config yes/no values and also model/select options which i cannot use in .xml structure (eg: ifconfig="value").
So I wish to load these files into the head block using the controller and do the echo if/else here so the appropriate configurations are loaded.
so far I have
public function indexAction(){
$this->loadLayout();
$this->renderLayout();
}
and I have been trying (just to start of from aka get working)
$this->getLayout()->getBlock('head')->append(
$this->getLayout()
->createBlock('core/text', 'some-unique-name')
->setText('<script type="text/javascript" src="/foo/baz/bar.js"></script>')
);
I have read some snippets and suggestions from Alan Snow but have been unsuccessful as I wish to have the generated xml load on each page as well but maybe that is not possible using the controller
any comments, help & opinions are very welcome.
Upvotes: 0
Views: 334
Reputation: 5670
As one should use existing methods you should do the following:
$this->getLayout()->getBlock('head')->addJs('javascriptfile.js');
Upvotes: 1