I've managed to 'fake' my way through the search bit by doing the following, and so long as I have css and js aggregation turned
off, this works, but I'm curious why when css+js aggregation is ON, it doesn't pull in the external resources from the CDN this way ... as I AM adding them with
url and not
file parameter.
I still have to learn how to do the getRepo(...)->search() bit correctly, but I'm far closer than I was. any pointers would be appreciated
Code:
<?php
// vim: set ts=4 sw=4 sts=4 et ft=php.html:
namespace XLite\Module\MHG\TemplateMods\View;
class PGPage extends \XLite\Module\CDev\SimpleCMS\View\CustomerPage implements \XLite\Base\IDecorator
{
public static function getAllowedTargets()
{
return array_merge(parent::getAllowedTargets(), array('page'));
}
public function getCSSFiles()
{
// find page id by its name
// $cnd is an object containing the condition for "page name is equal to ..." and if this search
// condition does not exist in the Repo class you have to create it as well for this to work
$cnd = new \Xlite\Core\CommonCell();
$cnd->enabled = true;
$cnd->name = "Photo Gallery";
$current_id = \XLite\Core\Request::getInstance()->id;
$targets = \XLite\Core\Database::getRepo('XLite\Module\CDev\SimpleCMS\Model\Page')->search($cnd);
/* {{{ Debug
foreach ($target_id as $k => $v) { $tgt[$k] = array('NAME' => $v->name, 'LABEL_ID' => $v->label_id, 'ID' => $v->id); }
$tgt = print_r($tgt, true);
\XLite\Logger::logCustom('MHG', "currentID: {$current_id} tgt: {$tgt} targetID: {$target_id}", false);
/* }}} */
$target_acquired = false;
foreach ($targets as $tk => $tv)
{
if ( ($tv->name == $cnd->name) && ($tv->id == $current_id) )
{
$target_acquired = true;
break;
}
}
if ( $target_acquired )
{
return array_merge(
parent::getCSSFiles(),
array(
array(
'url' => "//cdnjs.cloudflare.com/ajax/libs/nanogallery/5.9.1/css/nanogallery.min.css",
'media' => 'screen',
'no_minify' => true,
),
array(
'url' => "//cdnjs.cloudflare.com/ajax/libs/nanogallery/5.9.1/css/themes/light/nanogallery_light.min.css",
'media' => 'screen',
'no_minify' => true,
)
)
);
}
return parent::getCSSFiles();
}
public function getJSFiles()
{
$cnd = new \XLite\Core\CommonCell();
$cnd->enabled = true;
$cnd->name = 'Photo Gallery';
$current_id = \XLite\Core\Request::getInstance()->id;
$targets = \XLite\Core\Database::getRepo('XLite\Module\CDev\SimpleCMS\Model\Page')->search($cnd);
$target_acquired = false;
foreach ($targets as $tk => $tv)
{
if ( ($tv->name == $cnd->name) && ($tv->id == $current_id) )
{
$target_acquired = true;
break;
}
}
if ($target_acquired)
{
return array_merge(
parent::getJSFiles(),
array(
array(
'url' => "//cdnjs.cloudflare.com/ajax/libs/nanogallery/5.9.1/jquery.nanogallery.min.js",
'no_minify' => true
),
array(
'file' => 'modules/MHG/TemplateMods/nanogallery_local.js'
)
)
);
}
return parent::getJSFiles();
}
protected function getDefaultTemplate()
{
return 'modules/CDev/SimpleCMS/page/body.tpl';
}
}