I might be wrong on this but:
<?php
//this extracts the album number from the link provided by facebook which is passed as a template variable in the snippets &album parameter
$parts = explode('.', $album);
//creates the url for the JSON data using the album number we extracted with explode
$facebook_album = file_get_contents("http://graph.facebook.com/".$parts[3]."/photos?fields=source,name&limit=".$limit);
//decodes the JSON data
$dataArr = json_decode($facebook_album, true);
//for loop which sets a placeholder for the fields we will use from the provided JSON data
foreach ($dataArr['data'] as $d) {
//tells modx to apply the chunk to the output
$output .= $modx->getChunk($tpl, $d);
//if I used return it would only display the last result in the array echo displays all of the items I think this needs to be changed
}
return $output;
You dont really need to set placeholders unless you want to specifically set the names. You can just use [[+source]] and [[+name]]
$output .= $modx->getChunk($tpl, $d);
here, i incrementally add to ouput rather than returning individually.
the second value is the array being passed through.
applies the tpl values using the array.
See docs here for getChunk:
http://rtfm.modx.com/revolution/2.x/developing-in-modx/other-development-resources/class-reference/modx/modx.getchunk
Just a note about PHP snippets:
Anything you pass through the snippet with "&variable" (ie &tpl) automatically parses over to $tpl in the php script. (you can make whatever you want)
so to use this script you might use...
[[!getFacebookAlbums? &tpl=`facebookChunk.tpl` &parts=`whateverlinkgoeshere`]]
&parts value is assigned to $parts and &tpl is assigned to $tpl in the script.
Dont forget to update your chunks to use [[+source]] instead of [[+imageURL]] since we (i) removed the placeholders!
If you wanted to clean up your script a little better you could even bypass the string processing and input the album number manually instead of the using the link and add it to the params list:
[[!getFacebookAlbums? &album=`2501` &tpl=`facebookChunk.tpl`]]
<?php
//creates the url for the JSON data using the album number we extracted with explode
$facebook_album = file_get_contents("http://graph.facebook.com/".$album."/photos?fields=source,name&limit=".$limit);
...
[ed. note: eein!! last edited this post 10 years ago.]