We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6059
    • 45 Posts
    I create my own tv Input Tag and tried to use getresources but can not get it to run hope someone can help.

    $this->xpdo->lexicon->load('tv_widget');
    
    $properties = array(
    	'tpl'=>'schauspielerJsonList',
    	 'parents'=>'2'
    );
    
    $jsonString = $modx->runSnippet('getResources', $properties);
    
    //$jsonString = '{"name":"Arnold","id":"123"}';
    
    $elements = json_decode($jsonString);
    
    return 'elem: '.$jsonString;
    


    I create a chunk that should be field from get resources in json format, than decode it i work with it, but getresources give no data back. Do i need to run the ’runSnippet’ on another way for a custom TV INput?
      • 18373 ☆ A M B ☆
      • 3,141 Posts
      Would probably help to see the "schauspielerJsonList" template.


      And why wouldn’t you just use the Resource list input type? That will create a dropdown list of all resource under the ID you specify in the input options.
        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.
        • 6059
        • 45 Posts
        Here is the code of the ’schauspielerJsonList’ chunk

        {"name":"[[+pagetitle]]","id":"[[+id]]"}​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​


        I need it because i want to make a TV input where i can choose an Movie Actor and then write is movie role all in one TV. If i use the Resource Input Tag i can only choose the actor.
          • 18373 ☆ A M B ☆
          • 3,141 Posts
          I think it’s easier to just use MODX/xPDO objects instead..

          $this->xpdo->lexicon->load('tv_widget');
          
          $parent = $modx->getObject('modResource',2);
          $children = $parent->getMany('Children');
          if (empty($children)) { return; }
          
          $list = array();
          foreach ($children as $child) {
            $list[] = array(
              'name' => $child->get('pagetitle'),
              'id' => $child->get('id'));
          }
          
          return $modx->toJSON($list);
            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.
            • 3749
            • 24,544 Posts
            Maybe I’m misunderstanding you, but I think you’re making this more complicated than it needs to be.

            You send getResources() the selection and sorting criteria and the name of the Tpl chunk (with placeholders in it for the fields). getResources returns the HTML output for the screen.

            You want something more like this:

            <?php
            $this->xpdo->lexicon->load('tv_widget');
            
            $properties = array(
            	'tpl'=>'schauspielerJsonList',
            	 'parents'=>'2'
            );
            
            $local_where = array(
                  'name'=>'Arnold',
                  'id'=> '123',
            };
            
            $properties['where'] = $modx->toJSON($local_where);
            
            return 'Elem: ' . $modx->runSnippet('getResources', $properties);


            Obviously, this code can be shortened. I spread it out to make it easier to see what’s happening.
              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