Forum
Gallery support for blocks
Hi,
A few weeks ago you helped me add galleries via blocks to blog posts...
https://forum.grabaperch.com/forum/01-21-2016-gallery-in-a-block
I'm trying to do the same but on pages. So I'm using the gallery list field in a block to select a gallery to display on a page.
On on template I have the select field...
<perch:content id="album" type="albumlist" label="Image Gallery" suppress="true" />
On my page I have...
<?php perch_content('Page Content'); ?>
<?php
$album = perch_content_custom('Page Content', 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);
}
?>
This works fine but not inside a block.
On the gallery change log it says support was added for blocks. Is there a new function for this? Or do I need to do it in a similar way that it was done on blog posts (https://forum.grabaperch.com/forum/01-21-2016-gallery-in-a-block).
Thanks, Shawn
How is it failing? Have you inspected the contents of
$album
?The contents of the album seem to be ok.
But it does not display on the page if I have it set within a block
If I set it outside the block it does display
So have you updated your code to match the shape of the data?
I'm not sure I follow.
My id in the field tag is album
Is it not correct to have 'album' here?
If you look at the
print_r()
result,$album[0]['album']
doesn't exist. You need to update that reference to target the real location within the blocks.So you are saying I have to filter through the blocks like we did on the blog post I referenced? I'm able to get and show the gallery in a block using the same way I did there. Is that the correct way to do it on a regular page?
Got it to work. Thanks!
Page...
Template...