Area inside custom block
Permalink
Hey, I'm trying to do this and it worked:
Area is there (see screenshot 1). But, if I output area like this, then I can't edit parrent block. There's no JS event on a block that is used for editing (see screenshot 2). If I remove area from view.php of my block, it can be edited fine. My guess it's not possible at the moment. But maybe there's a way I can output some "switch" for administrator on front-end of site (not in edit mode) that will change some var in DB? This way I could add condition in view.php of my block - if "edit areas switch" is ON, then output area, if not then don't output them and content of parrent block will be edited as usual. Kida clumsy solution, I know, but this is the best way I can think of right now. So how do I add this switch on front-end that will change var in DB?
<?php defined('C5_EXECUTE') or die(_("Access Denied.")); global $c; ?> <div class="program-section"> <div class="program-icon"></div> <div class="program-title"><?=$title; ?></div> <div class="program-text"><strong>Тезисы к обсуждению:</strong><br><?=$text;?></div> <div class="program-blocks"> <?php $a = new Area('program-blocks'.$bID); $a->display($c); ?> </div> </div>
Area is there (see screenshot 1). But, if I output area like this, then I can't edit parrent block. There's no JS event on a block that is used for editing (see screenshot 2). If I remove area from view.php of my block, it can be edited fine. My guess it's not possible at the moment. But maybe there's a way I can output some "switch" for administrator on front-end of site (not in edit mode) that will change some var in DB? This way I could add condition in view.php of my block - if "edit areas switch" is ON, then output area, if not then don't output them and content of parrent block will be edited as usual. Kida clumsy solution, I know, but this is the best way I can think of right now. So how do I add this switch on front-end that will change var in DB?
Look at the core stack display block - its an 'internal' block that is used to insert a stack into a page. The stack is rendered inside an 'area'. That contains all the tricks and intricacies to solve your problem.
Wut? I don't get it, you talking about problem from first post or second?
I solved second problem btw, in view.php of a block it works like this
Now I ran into another problem. I declare area inside my block like this:
It turned out that $bID is changing every time I edit parrent block. Sooo now I need another uniquie ID of a block that stays the same every time.
I solved second problem btw, in view.php of a block it works like this
$c = $b->getBlockCollectionObject(); $c->isEditMode(); // now works
Now I ran into another problem. I declare area inside my block like this:
$a = new Area('program-blocks'.$bID);
It turned out that $bID is changing every time I edit parrent block. Sooo now I need another uniquie ID of a block that stays the same every time.
Okay, I finished this. I think I made it pretty easy to understand and work with (check screenshot). Button inside tip sets cookie "pr_edit_mode" to 1 and reloads page. This action removes area from the block and other tip appears instead with pretty much same button that sets cookie "pr_edit_mode" to 0 and reloads page again.
How I acheved uniquie ids for each block that will stay the same. I added my own field in db.xml and called it "uniquie_id". In view.php first I check if uniquie_id is numberic. If it's not then user creating new block, so I search biggest uniquie_id in my DB table, increase it by 1 and send it to controller via hidden input. And if it's numberic, then I just pass it thru to controller and it saves it with same number every time. Pretty tricky way but works fine.
How I acheved uniquie ids for each block that will stay the same. I added my own field in db.xml and called it "uniquie_id". In view.php first I check if uniquie_id is numberic. If it's not then user creating new block, so I search biggest uniquie_id in my DB table, increase it by 1 and send it to controller via hidden input. And if it's numberic, then I just pass it thru to controller and it saves it with same number every time. Pretty tricky way but works fine.
Blocks inside blocks is literally what saves us from the mess that users have to go trough to get some kind of flexibility in layouts.
I'm fighting with the same problems you had, just so I can allow users with one simple block to choose and create proper CSS Grid items with whatever content they want, without that they need to jump trough to many hooks and loops.
Thanks for sharing your experience with that, helps me a lot.
I'm fighting with the same problems you had, just so I can allow users with one simple block to choose and create proper CSS Grid items with whatever content they want, without that they need to jump trough to many hooks and loops.
Thanks for sharing your experience with that, helps me a lot.
So, I managed to do this with cookies. Checkbox on fron-end changes cookie "pr_edit_mode" to 1 or 0. And then I can add condition in view.php of block:
Now the problem is - this condition works both in edit mode and on fron-end. And adding $c->isEditMode() in view.php gives me error "Call to a member function isEditMode() on null". I checked this, $c var = NULL. How can I add this var inside view.php or controller.php of my custom block?