DESIGNfromWITHIN Reply #1, 3 months, 2 weeks ago
Can anybody figure out why my resolve.tv.template.php is not working?
I need to assing TV's to templates.
No errors, but the package simply adds the TV to all templates.
Full code here:
https://github.com/DESIGNfromWITHIN/Flexibility
My resolve.tv.template.php:
The code in build.transport.php:
I need to assing TV's to templates.
No errors, but the package simply adds the TV to all templates.
'footer_box_01' should only be added to: 'settings_template'
Full code here:
https://github.com/DESIGNfromWITHIN/Flexibility
My resolve.tv.template.php:
<?php
/**
* Associate Template Variables to Templates
*
* @package modxss
* @subpackage build
*/
if ($object && $object->xpdo) {
switch ($options[xPDOTransport::PACKAGE_ACTION]) {
case xPDOTransport::ACTION_INSTALL:
case xPDOTransport::ACTION_UPGRADE:
$modx =& $object->xpdo;
/* list of tvs and templates for each */
$tvs = array(
'footer_box_01' => array('settings_template'),
);
foreach ($tvs as $tvName => $templateNames) {
if (!is_array($templateNames) || empty($templateNames)) continue;
$tv = $modx->getObject('modTemplateVar',array('name' => $tvName));
if (empty($tv)) {
$modx->log(xPDO::LOG_LEVEL_ERROR,'Could not find TV: '.$tvName.' to associate to Templates.');
continue;
}
$rank = 0;
foreach ($templateNames as $templateName) {
$template = $modx->getObject('modTemplate',array('templatename' => $templateName));
if (!empty($template)) {
$templateVarTemplate = $modx->getObject('modTemplateVarTemplate',array(
'tmplvarid' => $tv->get('id'),
'templateid' => $template->get('id'),
));
if (!$templateVarTemplate) {
$templateVarTemplate = $modx->newObject('modTemplateVarTemplate');
$templateVarTemplate->fromArray(array(
'tmplvarid' => $tv->get('id'),
'templateid' => $template->get('id'),
'rank' => $rank,
),'',true,true);
if ($templateVarTemplate->save() == false) {
$modx->log(xPDO::LOG_LEVEL_ERROR,'An unknown error occurred while trying to associate the TV '.$tvName.' to the Template '.$templateName);
}
}
} else {
$modx->log(xPDO::LOG_LEVEL_ERROR,'Could not find Template '.$templateName);
}
$rank++;
}
}
break;
}
}
return true;The code in build.transport.php:
$vehicle->resolve('php',array(
'source' => $sources['resolvers'] . 'resolve.tv.template.php',
));What am I doing wrong?