Embed Simple Image Gallery into page

Permalink Browser Info Environment
I have been trying out the fantastic Simple Image Gallery add on from Jordan Lev.

I am currently working on a site with a large number of gallery pages and have been trying to embed this add on into the block along the same lines as hard coding an autonav block so that I can automatically grab the correct fileset on each page.

I have added the block manually to the page to test our custom template which works fine (http://toadhall.bluegreenhosting.co.uk/nurseries/horley/gallery/rooms/)

So far I have tried

$gal = BlockType::getByHandle('simple_image_gallery');


which throws an error relating to getPackageID()
I managed to get past this by adding 'packages' (as that is where the block is located presumably?)

$gal = BlockType::getByHandle('packages/simple_image_gallery');


I have figured out the various options from the form.php file

$gal->controller->fsID = '11';
$gal->controller->displayColumns = '2';
$gal->controller->thumbWidth = '150';
$gal->controller->thumbHeight = '150';
$gal->controller->enableLightbox = '1';
$gal->controller->fullWidth = '640';
$gal->controller->fullHeight = '640';
$gal->controller->lightboxTransitionEffect ='fade';
$gal->controller->lightboxTitlePosition = 'inside';


but the sticking point seems to be when it comes to render the page

$gal->render('templates/gallery');


which throws the error "Call to undefined method stdClass::render()"

I have also tried render('view') to bypass the custom template and view('view') ( Call to undefined method stdClass::view() ) with no luck.

Is embedding of blocks restricted to the core blocks contained within the "concrete/blocks" directory? If not is there a way to add the necessary functionality to allow the block to render in this way?

Type: Discussion
Status: New
phowie74
View Replies: View Best Answer
jordanlev replied on at Permalink Best Answer Reply
jordanlev
calling BlockType::getByHandle('package/simple_image_gallery') is a red herring in this case... you always need to pass in just the blocktype handle to that (not with the "packages/" thing in front).

The immediate problem you're having is caused by some code in the block controller that doesn't work when hardcoding the block on a page. I did some tests and was able to fix that particular issue, but then a bunch of other errors showed up subsequently. The moral of the story here is that you unfortunately can't hardcode this block into your page type templates.

An alternate solution is to put the block into a stack (maybe make a stack called "hardcoded content" or "global blocks -- DO NOT TOUCH" or something like that?), then after you've added the gallery block to the stack, click on the block and choose "Custom Template" from the popup menu. Enter a block name and save (for example "Rooms Gallery"). Remember to click the grey "Approve Changes" button at the top of the stack window.

Now, in your page type templates, use this code to "hardcode" that stack block:
<?php Block::getByName('Rooms Gallery')->display(); ?>


I'm actually of the opinion now that blocks should never be hardcoded into page type templates, for a lot of reasons (these buggy behaviours being one, another reason is because hardcoding a block bypasses C5's caching). The only downside to using the Stack method is that a user might accidentally remove or rename or change the block... but hopefully this can be addressed by giving the stack a name like "DO NOT TOUCH", or if you don't trust your users, then by turning on advanced permissions and disabling the editing of that stack.

Best of luck,
Jordan
phowie74 replied on at Permalink Reply
phowie74
Thanks so much for looking into this for me Jordan, I really appreciate it.

I can understand your viewpoint on hard coding blocks. I was just trying to think of a way I could pull in the File Set ID dynamically within a template rather than manually enter the block into each gallery page.

I will look into the Stack approach you mentioned as it seems like a good alternative.

Thank you once again for addressing my query and a big thank your for the block too which works really well.

Paul

concrete5 Environment Information

Browser User-Agent String

Hide Post Content

This will replace the post content with the message: "Content has been removed by an Administrator"

Hide Content

Request Refund

You have not specified a license for this support ticket. You must have a valid license assigned to a support ticket to request a refund.