In CakePHP 2.1, Blocks are a part of the core, and are used to display
content, scripts and css as a part of the layout.
You can start a block by simply writing to it, using any of the available
block commands (i.e. $this->start(), $this->assign(), $this->prepend(),
$this->append()), although your mileage may vary if you start appending to
a block that hasn't been created.
Your example is using trying to use nested elements, rather than blocks.
The strength of blocks is that you can write to them from helpers, layouts,
views and elements, and then choose to display the block at a later time
the view or layout processing.
Several helpers could write to a block that is displayed by an element, and
element would not need to know about those helpers. Without blocks, the
element would need to know about those helpers to display the content.
Regards
Reuben Helms
On Thursday, 13 December 2012 18:46:48 UTC+10, resting wrote:
>
> Why do we need a block? And where do we define it?
>
> I think templates are flexible, and I use them as partials and "blocks".
> Therefore I'm curious about how to use a block.
>
> For example, I could do this (if I'm not wrong):
>
> Views/index.ctp
>
> <?php echo $this->element('someBlock'); ?>
>
> Then in Views/Elements/someBlock.ctp
>
> <div>
> //some layout
> <?php echo $this->element('someBlockContent'); ?>
> </div>
>
> Then finally in Views/Elements/someBlockContent.ctp
>
> <div>
> <p>This is someBlockContent's content</p>
> </div>
>
> Nested templates works the same as a block?
>
--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
Visit this group at http://groups.google.com/group/cake-php?hl=en.