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

    Thanks alot for your valuable guides!!!
    I’ve learned alot from your posts and website.

    I’m a new modx revo adopter, in fact just trying to develop my own site.
    Here’s my steps so far:

    1. Create a new table in mysql (say: tf_Package and create corresponding xpdo model (using your tutorial on it) -- working well

    2. I need to display the tf_Package - one record a time.

    2a. Create a snippet with getCollection as in your tutorial, passed the record to placeholders. Create a template which call this snippet with corresponding placeholders -- working well. However, with this dynamic, I’m loosing the google search engine (SEO) compatibility, isn’t it?

    2b. Therefore I change the method to create new pages for every records of tf_Package. This time, I’m going to use several TVs. Individually all working well. However, when I try to create several snippets as follow:

    //snippet_name: qry_tbl_Trials
        $path = MODX_CORE_PATH . 'components/tf_package/';
        $result = $modx->addPackage('tf_package',$path . 'model/','tf_');
        $trials = $modx->getCollection('Trials', array('trialType'=>$par1, 'trialSubType'=>$par2,));
        return $trials;
    


    //snippet_name: createPage
    
    //Count the matching records
        [[qry_tbl_Trials? 
            &par1=`muscle`
            &par2=`upper`
        ]]
    
    //above step not working
    
    //For each record, get the record, create new page, assign record fields to corresponding TVs
    
    //Modify and decorate the template
    
    
    



    Would you please help why I cannot call the first snippet from the other?

    Anyway, thanks alot for your helpful posts. I’ll search the forum also.




      • 3749
      • 24,544 Posts
      You can’t use MODx tags in a snippet. You need to use this to run another snippet:

      <?php
      $params = array(
          'param1'=>'value1',
          'param2'=>'value2');
      };
      
      $result = $modx->runSnippet('SnippetName',$params);
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 29490
        • 2 Posts
        Thanks alot Bob
          • 44586
          • 1 Posts
          After years reading this post, there is now an easy way to create a document with TVs:
          Tested for modx revo 2.2.9 pl (traditional)

                      $doc = $modx->newObject('modDocument');
                      $doc->set('parent', 1); //document-id for parent (0 for root)
                      $doc->set('pagetitle', 'document title');
                      $doc->set('template', 2); //id of the template (no names)
                      $doc->set('published', 1); //1 = true
                      $doc->set('cacheable', 0); //0 = false
                      $doc->set('hidemenu', 1); //1 = true
                      $doc->setContent('<p>Main content</p>');
                      $doc->save(); //save to get a document id, to save tvs
                      $id = $doc->get('id');
                      if (!empty($id)) {
                          $doc->setTVValue('TVName', 'tv content'); //TVs can only be save, if the document has an ID
                          //saves the document in modressource.class.php see setTVValue, returns true or false
                      }
          
            • 3749
            • 24,544 Posts
            Here's something to try:


            if (empty($id)  {
                $modx->reloadContext('web');
            }
            if (!empty($id)) {
                $doc->setTVValue('TVName', 'tv content'); //TVs can only be save, if the document has an ID
                //saves the document in modressource.class.php see setTVValue, returns true or false
            }
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting