Block position
Permalink
I am in a situation where I would like to understand from within my Block view.php, what position I am in within the Area.
Is there a way that this can be achieved?
The broader scenario is that I am allowing my editors to build up a food menu with 'Menu Group' and 'Menu Item' blocks. As I haven't worked out how to embed one block into another (not sure if that should be possible by design anyhow), I wanted to wrap the first and last 'Item' (essentially a <li>) with the opening and closing <ul>.
Any ideas?
Regards,
Dan
Is there a way that this can be achieved?
The broader scenario is that I am allowing my editors to build up a food menu with 'Menu Group' and 'Menu Item' blocks. As I haven't worked out how to embed one block into another (not sure if that should be possible by design anyhow), I wanted to wrap the first and last 'Item' (essentially a <li>) with the opening and closing <ul>.
Any ideas?
Regards,
Dan
Ok, for the benefit of future searches, this is how I determined the order position of my Block within its Area, within the Block's view.php:
There may be a better way but I used this successfully to determine what was around my current block.
I have a niggling feeling that there is a better approach to this and I simply just haven't discovered it yet. I'll check out customising the display code within the parent template as this may be better.
Regards,
Dan
for ($i=0; $i<sizeof($blocks); $i++) { if($blocks[$i]->getBlockID() == $this->block->getBlockID()) { $blockPosition = $i; break; } }
There may be a better way but I used this successfully to determine what was around my current block.
I have a niggling feeling that there is a better approach to this and I simply just haven't discovered it yet. I'll check out customising the display code within the parent template as this may be better.
Regards,
Dan
C5's API reference (http://docs.concrete5addons.com/) is very useful for this. Visit the link, expand 'Class List' on the left and select 'Block'.
On the right-side you'll get the list of all members related to the Block. Some interesting for you (I guess) are:
* getAreaHandle() which return the area name and can be used in your block's view like:
* $arHandle is a public attribute that displays the area handle (same output as above).
Now, to wrap each of your blocks with some code, this surely has to go in your Theme and not the block itself.
When defining Areas in your theme, use the following method to add code before/after each block with a specified Area:
Hope this helps.
On the right-side you'll get the list of all members related to the Block. Some interesting for you (I guess) are:
* getAreaHandle() which return the area name and can be used in your block's view like:
<?php echo $this->block->getAreaHandle();?>
* $arHandle is a public attribute that displays the area handle (same output as above).
Now, to wrap each of your blocks with some code, this surely has to go in your Theme and not the block itself.
When defining Areas in your theme, use the following method to add code before/after each block with a specified Area:
<?php $area->setBlockWrapperStart('<li>'); $area->setBlockWrapperEnd('</li>');?>
Hope this helps.
Thanks okhayat,
Its seems obvious in hindsight that this code should go in the theme template and not here.
Thanks for pointing me in the right direction.
Dan
Its seems obvious in hindsight that this code should go in the theme template and not here.
Thanks for pointing me in the right direction.
Dan
I was missing this a few minutes ago.
I'll see where this takes me and post my findings.