Forum
Gallery in a block
Hi,
I'm having a problem getting a gallery to work in a block. I'm adding a gallery selection menu in the blog post form like this and it works fine.
<perch:blocks order="4">
<perch:block type="ImageGallery" label="Image Gallery">
<perch:blog id="album" type="albumlist" label="Blog Gallery" suppress="true" />
</perch:block>
</perch:blocks>
In my post.php file I have this to get the selected gallery...
<?php
$blog_album = perch_blog_post_field(perch_get('s'), 'album', true);
perch_gallery_album($blog_album);
?>
Then display using the template...
<perch:before>
<div id="owl-slideshow-multi" class="itemsScaleUp-true owl-carousel owl-theme">
</perch:before>
<div class="item">
<a href="<perch:gallery id="main" />" class='strip' data-strip-group-options="loop: true, maxWidth: 800" data-strip-caption="{$item.caption}" data-strip-group="{$item.belongs_to_gallery}" title="{$item.caption}">
<img src="<perch:gallery id="main" />" width="<perch:gallery id="small-w" />" height="<perch:gallery id="small-h" />" alt="<perch:gallery id="imageAlt" />" />
</a>
</div>
<perch:after>
</div>
</perch:after>
All of this works fine if I don't put the Gallery Select menu in a block. But if it is in a block the gallery does not show. No output at all.
Try adding
scope-parent="true"
on yourperch:blocks
tag, and then usingparent.album
from within the block.I added scope-parent="true" to the blocks tag but not sure exactly where to add parent.album from within the block.
Thanks
From the docs I think I see where I should change id="album" to id="parent.album"
I did that but now i get a block with no contents when trying to add and select a gallery. The block shows but the selection box is not there.
I have many more block between this same blocks tag. Should all of their id's be change to parent. ?
Sorry, I've got this backwards. I see the source of the album is in the blocks - I misunderstood.
Roll back those changes I just had you make - apologies.
The issue is that this line is going to be insufficient to access the content within blocks:
I think you're going to need to use
perch_blog_custom()
with theskip-template
option to get the data back. How's your PHP?No worries, I have rolled it back now.
Well my PHP skills are minimal at best. Mostly just find snipped code and try and make it work. lol
Ok, can you do this and let me know what it outputs?
Sure, this outputs my blog post. When placed in the blog/post.php file. It outputs the post contents using the perch/templates/post.html template.
I should also say it did not include the gallery. Here is a link
https://192.185.195.67/~eisenhowerpta/blog/post.php?s=2015-08-25-jog-a-thon
Sorry, I missed an attribute. That'll teach me to try and be helpful at 9pm on a Friday night!
No problem, It's very much appreciated. :) So adding that produced several arrays in-between normal content. You can see from the link in my last post. I see that the imageGallery block was also included in the arrays.
Ok, so we need to find the album slug in the data. Something like this should do it:
Yep that works! Awesome! Only problem is like other blocks it does not re-position on the page when moved in different order. It only shows on the bottom. I guess because I'm first calling the blog contents and then the gallery block?
Where it's output depends on where you then include the
Right but how can I get it to where it is part of the rest of the blocks on the page. As it is now it is in a block but I cant reorder on the page like a normal block. So it kind of defeats the purpose.
I would string replace it.
In your block template, add something like
<!-- ALBUM HERE -->
Then output your post to a variable.
and replace the string as you echo it.
That did it. Thanks for getting me through that, works great now.