I created a new snippet I call rotatead1. The PHP function works great outside of modx, but when I put the code in a snippet I get an error.
PHP error debug
Error: opendir('c:/wamp/www/modx/assets/banners/') [function.opendir]: failed to open dir: [b]No such file or directory[/b]
Error type/ Nr.: Warning - 2
File: C:\wamp\www\MODx\assets\snippets\rotate\readfiles.php
Line: 5
Line 5 source: $dir = opendir($banpath);
SNIPPET
----
if(!isset($banpath) || $banpath == '') { return; }
$RotatePath = $modx->config['base_path'] . 'assets/snippets/rotate/';
include_once($RotatePath.'readfiles.php');
$modx->setPlaceholder('banner',$imageoutput);
$imageoutput = rotate($banpath);
return $imageoutput;
----
NOTE - I used &placeholder=’1’ &output=’0’ when I tried the placeholde method.
Scott
MODx 1.0.2 Rev 6066 // Apache version 2.2.14 (Unix) // PHP version 5.2.11 // MySQL version 5.1.42 // Architecture x86_64 // Operating system: Linux
Does the directory ’c:/wamp/www/modx/assets/banners/’ exist?
If so, opendir() has some problems on Windows machines:
http://us2.php.net/function.opendir
BTW, it appears that you’re setting a placeholder with a variable that hasn’t been assigned yet:
$modx->setPlaceholder('banner',$imageoutput);
$imageoutput = rotate($banpath);
BobRay,
Thanks for your help. The snippet seems to be working excpet the image will not display.
When I view the source of the returned page the place holder is outside of my html and there are extra
that I did not add.
Section of my page where I put the snippet code
<div id="banright" >
[!rotateads1? &placeholders='1' &output='0' &bannerdir=assets/banners/!]
<a href="http://www.howtodoc.com"><img class="banrightimg" border="0" src="c:/wamp/www/modx/assets/banners/[+rotateads1.banner+]"/></a>
</div>
SNIPPET CODE (ROTATE() randomly grabs one of the image files)
$imageoutput=' ';
$retbanner=' ';
$bannerdir = (isset($bannerdir))? $bannerdir:'assets/banner/';
$modx->setPlaceholder('banner',$imageoutput);
$bannerpath = $modx->config['base_path'] . $bannerdir;
$rotatepath = $modx->config['base_path'] . 'assets/snippets/rotate/';
include_once($rotatepath.'readfiles.php');
$imageoutput = rotate($bannerpath);
return $imageoutput;
OUTPUT: MODX returned the OUTPUT and placed it above the HTML line
<div id="banright" >
<br/> sample_ad_003.bmp
<a href="http://www.howtodoc.com"><img class="banrightimg" border="0" src="c:/wamp/www/modx/assets/banners/ "/></a>
</div>
Scott
MODx 1.0.2 Rev 6066 // Apache version 2.2.14 (Unix) // PHP version 5.2.11 // MySQL version 5.1.42 // Architecture x86_64 // Operating system: Linux
Give this setup a try:
Section of the page where you put the snippet code, note the removal of the snippet name from the placeholder, it has to match what you set as the placeholder name in the snippet, in this case [+banner+].
<div id="banright" >
[!rotateads1!]
<a href="http://www.howtodoc.com"><img class="banrightimg" border="0" src="c:/wamp/www/modx/assets/banners/[+banner+]"/></a>
</div>
SNIPPET CODE (ROTATE() randomly grabs one of the image files)
<?php
$imageoutput='';
$retbanner='';
$bannerdir = (isset($bannerdir))? $bannerdir : 'assets/banner/';
// move this down to the bottom since this is the actual value you need to produce the image name
//$modx->setPlaceholder('banner',$imageoutput);
$bannerpath = $modx->config['base_path'] . $bannerdir;
$rotatepath = $modx->config['base_path'] . 'assets/snippets/rotate/';
include_once($rotatepath.'readfiles.php');
$imageoutput = rotate($bannerpath);
$modx->setPlaceholder('banner',$imageoutput); // usage: [+banner+]
//return $imageoutput;
?>
Hope this helps
BobRay,Breezer,
Many thanks.

I think I’m closer to a resolution.
tkfm,
thanks for reminding me about backticks.
Section of my Template where I call my Snippet
<div id="banright" >
[!rotateads1? &placeholders=`1` &output=`0` &bannerdir=`assets/banners`!]
<a href="http://www.howtodoc.com"><img class="banrightimg" border="0" src="c:/wamp/www/modx/assets/banners/[+banner+]"/></a>
</div>
The SNIPPET: rotate() returns a random file form the banner directory.
$imageoutput=' ';
$bannerpath = $modx->config['base_path'] . 'assets/banners/';
$rotatepath = $modx->config['base_path'] . 'assets/snippets/rotate/';
include_once($rotatepath.'readfiles.php');
$imageoutput = rotate($bannerpath);
$modx->setPlaceholder('banner',$imageoutput);
PAGE SOURCE --- OUTPUT from MODX
<div id="banright">
<br/>
<a href="http://www.howtodoc.com"><img class="banrightimg" border="0" src="c:/wamp/www/modx/assets/banners/sample_ad_003.bmp"/></a>
</div>
My link <a href..> above looks correct now.

But the image still is not showing.
Scott
MODx 1.0.2 Rev 6066 // Apache version 2.2.14 (Unix) // PHP version 5.2.11 // MySQL version 5.1.42 // Architecture x86_64 // Operating system: Linux
tkfm,
BINGO!!!!!! That’s the finaly piece. My banner is rotating. w0ot! Yes!
src="[(base_url)]assets/banners/[+banner+]"
Many Thanks to all for all your help.
:)
Scott
MODx 1.0.2 Rev 6066 // Apache version 2.2.14 (Unix) // PHP version 5.2.11 // MySQL version 5.1.42 // Architecture x86_64 // Operating system: Linux
It looks like this rotate banners when the page refreshes.
Can this be setup to rotate the banner at a set time?