Custom Slideshow Captions for Exhibit Summary Page

We're trying to make our Exhibit summary pages a little more interesting with the layout and have incorporated a slideshow. Because of how Exhibit Builder uses the summary.php page we have to keep the page generic for all exhibits using the slug as a variable to specify the path to the correct images (for example: <?php echo WEB_ROOT;?>/themes/slideshows/<?php echo html_escape(exhibit('slug')); ?>/data1/images/1.jpg). However, I haven't yet been able to figure out how to insert variables to create captions. The text between the anchor tags is styled to create captions, but I have to keep them generic with a variable such as $caption1, $caption2, etc. When I set a value for $caption1 at the top of the summary.php page my caption works just fine. But what I really want to do is call in the variables from outside this page so that I can customize them for each exhibit like I have for the images. I tried creating a captions.php file in the same directory as the images:

$caption1 = "Caption example here";

But how do I call this from my summary.php file? I tried require_once, require, and include but I don't think I have the script right.

Adding a require_once at the top of summary.php should do the trick. Do you get any error message when trying require_once? My first guess would have been something wrong with the path to the file, but that should cause an error. It might help to turn on the error logging to see if that shows any more information.

I re-tried require_once with the following code:

require_once 'captions.php'; ?>

And for the purposes of testing I moved my captions.php to the same folder as the summary.php file.

I turned on the error log but nothing appears in it. What happens is that the page stops generating when it hits the require_once code. I moved it from the top of the page to just above the call for the footer and that causes it to show the page up to the footer. I thought I would try slapping a require_once summary.php within the captions.php to try to re-route it but no luck so far. Any ideas on how to both call the values in my captions.php and generate the full summary.php page?

That would make me expect there to be an error in captions.php itself. Is there more in it than the example you gave? If so, could you post it?

That's it for the code on captions.php which is now:

$caption1 = "The Liberty Ship SS Janet Lord Roper";

I just finally got it partially working (I think I may not have had captions.php in the correct folder for testing before). It seems to work if and only if I put captions.php in the same folder as summary.php. When I instead try:

require_once '<?php echo WEB_ROOT;?>/themes/slideshows/<?php echo html_escape(exhibit('slug')); ?>/captions.php'; ?>

it doesn't work. I need to be able to direct to different captions.php files in different folders depending on the exhibit in question. Am I making an error in trying to use require_once to call captions.php from a different location?

The page in question that I am testing this out on is:

You don't echo things to include them in PHP code, and you don't want to use WEB_ROOT when including PHP code, because you want a local path, not a URL.

Your require_once should be more like:

require_once THEME_DIR . '/slideshows/' . exhibit('slug') . '/captions.php';

That worked perfectly, thanks so much!