Problems, need help? Have a tip or advice? Post it here.
2 posts Page 1 of 1
Hi,

I don't know if my title for this topic/question is the best. I don't really know how to explain it very well, but I will give it a go.

Basically I want to create a photo gallery. I could do it the normal way with a clonable template, and insert images into an editable region. I just want to try and do it a bit simpler.

I've found a short little php snippet that will display all images from a folder on my server. Here is the php code I've found:

Code: Select all
<?php 
$files = glob("photographs/greenhouse/*.*");
for ($i=0; $i<count($files); $i++)
{
      $num = $files[$i];
      echo '<img src="http://agoberg.tv/'.$num.'" alt="random image">'."&nbsp;&nbsp;";
      }
?>


This works if I put some images inside a folder called greenhouse. What I want to be able to do tho is to use a code similar to this with some couch commands:

Code: Select all
<?php 
$files = glob("photographs/<cms:show photography_folder />/*.*");
for ($i=0; $i<count($files); $i++)
{
      $num = $files[$i];
      echo '<img src="http://agoberg.tv/'.$num.'" alt="random image">'."&nbsp;&nbsp;";
      }
?>


You might see the Couch field called photography_folder. I have created a clonable template where I have a field where I want to input the name of the folder I've uploaded some photos to. The problem is that the php code doesn't work when I use the couch command. By using this php snippet with couch I could display all images in a folder very easily without having to manually insert them into an editable region.

Any idea how I could fix this?
Hi,

You have explained the problem very well indeed.

As a solution. you can try using Couch cms:php tag instead of the native <?php.
This way other Couch tags can be within the enclosed PHP code.
The revised code will now become:
Code: Select all
<cms:php>
$files = glob("photographs/<cms:show photography_folder />/*.*");
for ($i=0; $i<count($files); $i++)
{
      $num = $files[$i];
      echo '<img src="http://agoberg.tv/'.$num.'" alt="random image">'."&nbsp;&nbsp;";
      }
</cms:php>

Please let me know if this helps.
2 posts Page 1 of 1
cron