We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 49438
    • 8 Posts
    Hi,

    Is it possible to dynalically create TVs in a snippet? For e.g I have the following code in a snippet:

    if (condition) {
                    $tvs = $modx->newObject(modTemplateVar);
                    $tvs->set('name'=>'newTemplate');
                    /*more settings*/
                    $tvs->save();
    }
    


    I know I may need to assign it to a template and set few more porperties but in theory is it possible to do this? I have been searching about it in the forums about creating new objects via newObject method but couldn't find one about template variables.

    Any help would be much appreciated. Thanks!
      • 4172
      • 5,888 Posts
      What is the purpose for creating TVs by a snippet here?

      It is possible with something like that:

                      $tv = $modx->newObject('modTemplateVar');
                      $tv->set('name'=>'newTemplateVar');
                      /*more settings*/
                      $tv->save();

        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 49438
        • 8 Posts
        Thanks for the reply Bruno. I noticed the missing single quotes after posting the question and TheBoxer helped me out. Basically there is a CSV input file which I am importing which should create TVs on the fly for a specific template. The above code is working now. Thanks for the help!

        Quote from: Bruno17 at Dec 01, 2014, 08:30 AM
        What is the purpose for creating TVs by a snippet here?

        It is possible with something like that:

                        $tv = $modx->newObject('modTemplateVar');
                        $tv->set('name'=>'newTemplateVar');
                        /*more settings*/
                        $tv->save();