We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10596
    • 18 Posts
    Hi I'm stuck with this output, please suggest what's wrong:

            $responsexml = @simplexml_load_string($result, 'SimpleXMLElement', LIBXML_NOCDATA | LIBXML_NOBLANKS);
    	foreach ($responsexml as $hotelresponse)
    	 {
    		$hotelname = ($hotelresponse->HotelInfo->Name);
    		$hoteldestination = ($hotelresponse->HotelInfo->Destination->Name);
    		$hotelcategory = ($hotelresponse->HotelInfo->Category);
    		$hotelimage = ($hotelresponse->HotelInfo->ImageList->Image[0]->Url);
    
    		$returnedoutput .= $modx->getChunk('_testxmlchunk',array(
      			'hotel' => $hotelname,
      			'destination' => $hoteldestination,
      			'category' => $hotelcategory,
      			'image' => $hotelimage,
    		));
              }
    
    return $returnedoutput;
    

    _testxmlchunk chunk template:

    <li>this is <b>[[+hotel]]</b> is in <b>[[+destination]]</b> category <b>[[+category]]</b> pic <img src="[[+image]]"/></li>

    It returns only the blank chunk template

    <li>this is <b></b> is in <b></b> category <b></b> pic <img src=""/></li>



    but when I do this.. it works

    $responsexml = @simplexml_load_string($result, 'SimpleXMLElement', LIBXML_NOCDATA | LIBXML_NOBLANKS);
    	foreach ($responsexml as $hotelresponse)
    	 {
    		$hotelname = ($hotelresponse->HotelInfo->Name);
    		$hoteldestination = ($hotelresponse->HotelInfo->Destination->Name);
    		$hotelcategory = ($hotelresponse->HotelInfo->Category);
    		$hotelimage = ($hotelresponse->HotelInfo->ImageList->Image[0]->Url);
    
    		$returnedoutput .= $hotelname.' '.$hotelimage.' '. $hoteldestination.' '.$hotelcategory.';
             }
    
    return $returnedoutput;
    



    any suggestion... Did I miss something? I want to template my snippet.


    I use:
    MODX Revolution 2.2.10-pl (advanced)
    mysql 5.5.37-35.0
    PHP Version 5.4.29

    This question has been answered by gee. See the first response.

    [ed. note: gee last edited this post 12 years, 4 months ago.]
    • discuss.answer
      • 10596
      • 18 Posts
      I found the solution, I should set placeholder

      $responsexml = @simplexml_load_string($result, 'SimpleXMLElement', LIBXML_NOCDATA | LIBXML_NOBLANKS);
      foreach ($responsexml as $hotelresponse)
       {
          $hotelname = ($hotelresponse->HotelInfo->Name);
          $hoteldestination = ($hotelresponse->HotelInfo->Destination->Name);
          $hotelcategory = ($hotelresponse->HotelInfo->Category);
          $hotelimage = ($hotelresponse->HotelInfo->ImageList->Image[0]->Url);
      
          
          //////add this/////SET THE PLACEHOLDER START/////////////
          $modx->setPlaceholder('hotel',$hotelname);
          $modx->setPlaceholder('destination',$hoteldestination);
          $modx->setPlaceholder('category',$hotelcategory);
          $modx->setPlaceholder('image',$hotelimage);
          /////add this////SET THE PLACEHOLDER END//////////////
      
          $returnedoutput .= $modx->getChunk('_testxmlchunk',array(
              'hotel' => $hotelname,
              'destination' => $hoteldestination,
              'category' => $hotelcategory,
              'image' => $hotelimage,
          ));
      
      
        }
      return $returnedoutput;