We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26503
    • 620 Posts
    I have an extra with a function in it:

    public function displayData($scriptProperties){
    		
    		$view = $scriptProperties['view'];
    		
    		$dataOut = '';
    		
    		switch ($view){
    			
    			// display program data
    			case 'programs' :
    
    			$programs = $this->modx->getCollectionGraph('Programs', '{ "ProgramNames":{},"Locations":{},"StatusFlags":{} }');
    			
    			if(!$programs) return 'not a collection';
    			
    			foreach ($programs as $program){
    
    				if (is_object($program)){
    
    					$programData = $program->toArray();  
    					$programData['prog_name'] = $program->ProgramNames->get('name');
    					$programData['prog_comment'] = $program->ProgramNames->get('comment');
    					$programData['status_flag'] = $program->StatusFlags->get('flag');
    					$programData['loc_name'] = $program->Locations->get('location');
    				      
    				}
    
    				$dataOut .= $this->modx->getChunk('ProgramsViewRowTpl',$programData);
    				echo '<pre>';print_r($dataOut);echo '</pre>'; // shows content of $dataOut
    			}
    				echo '<pre>';print_r($dataOut);echo '</pre>'; // shows nothing!! blank page
    			$output = $this->modx->getChunk('ProgramsViewWrapperTpl',array('programdata'=>$dataOut,));
    
    			return $output;
    					
    			break;
    			
    			
    		}
    		
    	} // end getPrograms




    It was working perfectly, displaying output in a nice table. Now when I run it, the only thing I get is the content of ProgramsViewRowTpl [if I view the source] ONLY, no html for the template is there, nothing only the output of the ProgramsViewRowTpl.

    here is ProgramsViewWrapperTpl: [this is not displayed]
    <!-- ProgramsViewWrapperTpl -->
    
    <table class="table">
    
    	<thead>
    	
    		<tr>
    		
    			<th>Location</th>
    			
    			<th>Fund</th>
    			
    			<th>Start Balance</th>
    			
    			<th>End Balance</th>
    						
    			<th>Start Date</th>
    			
    			<th>End Date</th>
    
    			<th>Status</th>
    		
    		</tr>
    	
    	</thead>
    	
    	<tbody>
    	
    		[[+programdata]]
    	
    	</tbody>
    
    </table>


    and here is ProgramsViewRowTpl :
    <!-- ProgramsViewRowTpl -->
    <tr>
    
    	<td>[[+loc_name]]</td>
    
    	<td>[[+prog_name]]</td>
    
    	<td>[[+start_balance]]</td>
    
    	<td>[[+end_balance]]</td>
    
    	<td>[[+start_date]]</td>
    
    	<td>[[+end_date]]</td>
    
    	<td>[[+status_flag]]</td>
    
    </tr>
    
    <!--[[+id]][[+created]][[+modified]][[+status_id]][[+location_id]][[+program_name_id]][[+start_date]][[+end_date]][[+start_balance]][[+end_balance]][[+comment]][[+prog_name]][[+prog_comment]][[+status_flag]][[+loc_name]]-->



    everything seems to execute fine right up until:$output = $this->modx->getChunk('ProgramsViewWrapperTpl',array('programdata'=>$dataOut,));

    any ideas???

      *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

      Sean Kimball CLP, CLS.
      Technical Director / Sr. Developer | BigBlock Studios
      ._______________________________________________.
      Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
      27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
      phone/fax: 905-426-5525
      • 40706
      • 128 Posts
      $this-> is only viable inside objects, but this in an function. You have to replace $this->modx with $modx and need an
      global $modx;
      at the beginning of your function.

      but beware... if the snippet is called twice the function is declared twice, so u should wrap it with an function_exists() condition.
        • 26503
        • 620 Posts
        I did get this working, sorry, I forget what the issue was.

        Also - I didn't really give you enough info - that function is wrapped in a class, so the $this-> is correct and $modx is passed in already



        Quote from: m.engel at Feb 26, 2014, 02:32 AM
        $this-> is only viable inside objects, but this in an function. You have to replace $this->modx with $modx and need an
        global $modx;
        at the beginning of your function.

        but beware... if the snippet is called twice the function is declared twice, so u should wrap it with an function_exists() condition.
          *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

          Sean Kimball CLP, CLS.
          Technical Director / Sr. Developer | BigBlock Studios
          ._______________________________________________.
          Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
          27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
          phone/fax: 905-426-5525