Correct usage of view blocks in 2.1
I think that I may be misunderstanding how View Blocks in 2.1 are supposed to work.
I am trying to wrap the site navigation (in the layout) in a view block, so that I can hide it from other views (registration form in this case).
I've read through the documentation and here is what I expected to work:
// In the layout
<nav class="site-navigation">
<div class="container">
<?php $this->start('site-navigation'); ?>
// The HTML here for the navigation menu ...
<?php $this->end(); ?>
</div>
</nav>
I expected that this would take my navigation HTML, stick it in the 'site-navigation' block, and display it.
The first problem was that it didn't display so just after the call to $this->end() I added
<?php echo $this->fetch('site-navigation'); ?> to display the menu.
Then at the top of my registration form view I have
<?php $this->assign('site-navigation', ''); ?> to hide the 'site-navigation' content on the registration page.
Unfortunately, this didn't work, the navigation menu is still displayed.
Can anyone point me in the right direction? Are view blocks suitable for my task or have I misunderstood their purpose?
Thanks in advance.
Asked by citalan, on 13/2/12
1 Answer
start() and end() are just capture blocks, it will save with a block name some html for later. You need to thinks about blocks in terms of layout - template. The templates define the block contents, but it is the layout which echoes them in the correct place.
So, in one file you usually assign/fill blocks with content, and in your layout (or sublayout) you echo those blocks at will.
Answered by lorenzoon 13/2/12
Ah, I see. I was expecting view blocks to work in the same fashion as Twig blocks did, which I had previously been using.
Not to worry, I'll just wrap the navigation in an if() check instead. Thanks for the help.
citalan - on 13/2/12
Rating
0
Viewed
504 times
Last Activity
on 14/2/12






