Forum

Thread tagged as: Question, Discussion, Gallery

How can I allow the client to choose a gallery and it outputs all the images of...

I want the client to be able to select the gallery that goes with a vehicle. So I have a dropdown in the template, that shows the galleries available.

Template:

<perch:content id="album" type="albumlist" label="Album" />

The above code is just out putting the slug for the album, which is correct, but I want to be able to take that slug and show the images for that gallery, so I can build a slider.

On the page, I've tried various things, this is what I have and its not working.

      <?php
        $albumSlug = $album[0]['album'];
        perch_gallery_album($albumSlug);

        if(perch_get('s')) {
          perch_gallery_album_images(perch_get('s'), array(
            'template' => 'gallery_slider.html',
            'image'    => true
          ));
        }
      ?>

So that doesn't work:

Array
(
    [type] => 8
    [message] => Undefined variable: album
    [file] => /public_html/stock/vdp.php
    [line] => 10
)

So how do I pass that slug album id to my page from the template once the user can selected it?

Health check

 PHP 5.5.38 is up to date
 MySQL 5.5.5-10.0.28-MariaDB is up to date
 Image processing available
Summary information

Perch: 3.0, PHP: 5.5.38, MySQL: mysqlnd 5.0.11-dev - 20120503 - $Id: 15d5c781cfcad91193dceae1d2cdd127674ddb3e $, with PDO
Server OS: Linux, cgi-fcgi
Installed apps: content (3.0), assets (3.0), categories (3.0)
App runtimes: <?php $apps_list = [ ];
PERCH_LOGINPATH: /cms
PERCH_PATH: /home/sites/sitename.com/public_html/cms
PERCH_CORE: /home/sites/sitename.com/public_html/cms/core
PERCH_RESFILEPATH: /home/sites/sitename.com/public_html/cms/resources
Image manipulation: GD
PHP limits: Max upload 64M, Max POST 64M, Memory: 128M, Total max file upload: 64M
F1: 0c66c2e1f82f9e0b7617b2cb8270f2c7
Resource folder writeable: Yes
HTTP_HOST: sitename.com
DOCUMENT_ROOT: /home/sites/sitename.com/public_html/
REQUEST_URI: /cms/core/settings/diagnostics/
SCRIPT_NAME: /cms/core/settings/diagnostics/index.php
Juan Fernandes

Juan Fernandes 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Where is $album created?

Well its not, I think, I tried using this code, mentioned here: https://docs.grabaperch.com/addons/gallery/fieldtypes/ - but that was saying that the region didn't exist.

<?php
    $album = perch_content_custom('My region', array('skip-template'=>true));
    if (is_array($album)) {
        // ['album'] is the ID of the field to get the slug from
        $albumSlug = $album[0]['album'];
        perch_gallery_album($albumSlug);
    }
?>

I want to be able to take the album slug and use that to show the images that go with that album.

As you can probably tell, i have no idea what I am doing, I know what I want to do :/

So using this code, I can show the images I need, but here I am hard coding the gallery ID.

      <?php perch_gallery_album_images("car-1", array(
        'template'=>'gallery_slider.html'
        ));
      ?>

The user is selecting the gallery via the vehicle_details templates, which is bellow the above code, so I thought there is no way it can work.

      <?php
        perch_content_custom('Vehicles', array(
         'template' => 'vehicle_detail.html',
         'page'     => '/stock/index.php',
         'filter'   => 'slug',
         'match'    => 'eq',
         'value'    => perch_get('s'),
         'count'    => 1,
        ));
      ?>

So I need to work out how to get the gallery id into the page before the vehicle_details template. So I may need to move this code elsewhere:

<perch:content id="album" type="albumlist" label="Album" />

I'm using list and detail, i have a stock page that lists the cars:

            <?php
              perch_content_create('Vehicles', array(
                'template'  => 'vehicle_detail.html',
                'multiple'  => true,
                'edit-mode' => 'listdetail',
              ));

              perch_content_custom('Vehicles', array(
                'template' => 'vehicle_listing.html',
                'filter'=>'sold',
                'match'=>'neq',
                'value'=>1
              ));
            ?>

Can I somehow pass the gallery id from /stock/index.php to the vehicle details page?

Duncan Revell

Duncan Revell 78 points
Registered Developer

$vehicle = perch_content_custom('Vehicles', array( 
'template' => 'vehicle_detail.html', 
'page' => '/stock/index.php', 
'filter' => 'slug', 
'match' => 'eq', 
'value' => perch_get('s'), 
'count' => 1, 
'skip-template' => true,        // we are getting all the content and storing it in $vehicle
'return-html' => true,         // we are also processing the template and storing the output
));
$album = $vehicle[0]['album'];        // grabbing the value of the album id from the vehicle

perch_gallery_album_images($album, array( 
'template'=>'gallery_slider.html' 
));

echo $vehicle['html'];          //  and here we are outputting the template html from up there

Oh my gosh, thank you so much Duncan! It works.