We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17499 ☆ A M B ☆
    • 872 Posts
    Hello,

    I’m trying to create a transport package for a template.

    So far, so good, installation has gone well, all directories, templates and TV’s are being installed but i’m stuck when i want to associate the TV’s to the template.

    Can somebody give me a hint on how to achieve that?

    My code:

    <?php
    /* create category */
    $category= $modx->newObject('modCategory');
    $category->set('id',1);
    $category->set('category','My template');
    
    /* create the templates */
    $template= $modx->newObject('modTemplate');
    $template->set('id',0);
    $template->set('templatename', 'My template name');
    $template->set('description', 'Cool description');
    $template->set('content',file_get_contents($sources['source_tpl'].'/tpl.html'));
    
    /* create the Template variable */
    $tvContent = $modx->newObject('modTemplateVar');
    $tvContent->set('id',0);
    $tvContent->set('type','option');
    $tvContent->set('name','content');
    $tvContent->set('caption','Principal content');
    $tvContent->set('elements','Normal content==Normal||Subnav content==Subnav');
    $tvContent->set('display','delim');
    $tvContent->set('display_params','&delimiter=||');
    $tvContent->set('default_text','Normal');
    
    $category->addMany($tvContent);
    $category->addMany($template);
    
    //This is where i'm stuck - I Don't know how to associate the tv to the template
    


      • 26903
      • 1,336 Posts
      You have to write a ’resolver’ to do this, this is php code that runs during the installation after the entities have been created, you can then link them as you wish as they now have ’real’ id’s.
      Have look at some in the components directories, try here as an example http://svn.modxcms.com/svn/modx-components/editarea/trunk/_build/resolvers/
        Use MODx, or the cat gets it!
        • 17499 ☆ A M B ☆
        • 872 Posts
        Thanks Shamblett, i’ll take a look! smiley

        edit: It worked like a charm, thanks again.