We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 29597 ☆ A M B ☆
    • 350 Posts
    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.

    '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?

    This question has been answered by markh. See the first response.

    [ed. note: ThaClown last edited this post 14 years, 7 months ago.]
      MODX Ambassador (NL) | Responsive web design specialist, developer & speaker
      DESIGNfromWITHIN, MPThemes and Any Screen Size
      Follow me on Twitter | Read my blog | My code on GitHub
    • discuss.answer
      • 18373 ☆ A M B ☆
      • 3,141 Posts
      I thought I posted here yesterday...???

      Anyway.

      Are you adding those templates in the build as well? Can you show the related part there?
        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
        • 29597 ☆ A M B ☆
        • 350 Posts
        Hey Mark,

        Thanks I just now fixed it... there was some code in resolvers/install.script.php
        That reset all the TV's to all templates....

        All working now!
          MODX Ambassador (NL) | Responsive web design specialist, developer & speaker
          DESIGNfromWITHIN, MPThemes and Any Screen Size
          Follow me on Twitter | Read my blog | My code on GitHub