← Back to Back To Front Support
I use in my Controller this code, for own assets:
public function __construct()
{
parent::__construct();
$this->addCss("/plugins/vedev/realty/assets/css/offers.css", "1.0.0");
$this->addJs("/plugins/vedev/realty/assets/js/offers.js", "1.0.0");
BackendMenu::setContext('Vedev.Realty', 'realty', 'offers');
}
In backend this work, in backtofront not.
I fix it write to cms page code section:
function onInit() {
// FIX assets
$this->addCss("/plugins/vedev/realty/assets/css/offers.css", "1.0.0");
$this->addJs("/plugins/vedev/realty/assets/js/offers.js", "1.0.0");
}
Is there a way to not reconnect resources on the page manually?
It’s hard to say right away. The problem is that the backend-controller is not involved at all when building the external controller. Can try to reach the backend-controller through some event (or BackendAuth) and pull out assets from there to merge with the main (I didn’t find such an event, probably figure something out later). It’s easier to make the addition of assets in a separate static function of the class, this will be easier (one point for resurses change)....
Last updated
I suggest the following solution in your component:
public function onRun()
{
foreach ($this->assets['css'] as $value) $this->page->addCss($value,'core');
foreach ($this->assets['js'] as $value) $this->page->addJs($value,'core');
$pageAssets = $this->page->getAssetPaths();
foreach($this->controller->getAssetPaths() as $type => $cAssets) {
$pAssets = $pageAssets[$type];
foreach($cAssets as $asset) {
if(!in_array($asset, $pAssets))
$this->page->{'add'.ucfirst($type)}($asset);
}
}
}
The goal is to add controller resources excluding duplicates.
Last updated
1-3 of 3