Jump to content

ralberts

Members
  • Posts

    31
  • Joined

  • Last visited

  • Days Won

    2

Posts posted by ralberts

  1. Hi folks,

    I'm looking to return results from PW in an Ajax call, but I'm not sure if I'm going about this the right (or preferred) way.

    I created a script in /htdocs/public/ajax/affiliates.php, which is called using Ajax.

    The script itself bootstraps Processwire and returns JSON for all affiliates. It looks something like this:

    <?php
    
    require_once '../../index.php';
    
    $data['markers'] = array();
    
    $markers = array();
    $affiliates = wire()->pages->find("template=affiliate");
    foreach ($affiliates AS $affiliate)
    {
    	$marker['latitude'] = $affiliate->mapmarker->lat;
    	$marker['longitude'] = $affiliate->mapmarker->lng;
    	$marker['title'] =  $affiliate->title;	
    
    	$data['markers'][] = $marker;
    }
    
    print(json_encode($data));
    

    The problem here is that $affiliate->title returns an object (LanguagesPageFieldValue), instead of the actual string I would expect it to do.

    I'm not sure where I'm going wrong here. I may have to manually set the language, call the title in a another manner, or just use a different approach alltogether. Any help is much appreciated :-)

  2. Sorry about highjacking this topic, but the subject seems fit. Wouldn't it be nice if the image itself had a multilanguage option too? After all: images might as well contain text. A banner image would be an obvious example. I currently see no easy way to differentiate between languages in order to display the correct image.

×
×
  • Create New...