Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Difference between Blocks and templates
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
resting  
View profile  
 More options Dec 13 2012, 3:46 am
From: resting <roy.wong...@gmail.com>
Date: Thu, 13 Dec 2012 00:46:48 -0800 (PST)
Local: Thurs, Dec 13 2012 3:46 am
Subject: Difference between Blocks and templates

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?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
resting  
View profile  
 More options Dec 13 2012, 3:59 am
From: resting <roy.wong...@gmail.com>
Date: Thu, 13 Dec 2012 00:59:59 -0800 (PST)
Local: Thurs, Dec 13 2012 3:59 am
Subject: Re: Difference between Blocks and templates
 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Reuben  
View profile  
 More options Dec 13 2012, 6:48 pm
From: Reuben <reuben.he...@gmail.com>
Date: Thu, 13 Dec 2012 15:48:29 -0800 (PST)
Local: Thurs, Dec 13 2012 6:48 pm
Subject: Re: Difference between Blocks and templates

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
resting  
View profile  
 More options Dec 14 2012, 3:47 am
From: resting <roy.wong...@gmail.com>
Date: Fri, 14 Dec 2012 00:47:58 -0800 (PST)
Local: Fri, Dec 14 2012 3:47 am
Subject: Re: Difference between Blocks and templates

Thanks for the information.

Is there a good example where using a block is more sensible as compared to
template?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Reuben  
View profile  
 More options Dec 16 2012, 5:43 pm
From: Reuben <reuben.he...@gmail.com>
Date: Sun, 16 Dec 2012 14:43:42 -0800 (PST)
Local: Sun, Dec 16 2012 5:43 pm
Subject: Re: Difference between Blocks and templates

First, we should probably start by using the terminology that is used by
CakePHP.  We have layouts, views, elements and blocks.  Layouts, views and
elements all use CakePHP templates, as denoted by the extension "ctp".

As a result, blocks complement templates, whether it be layouts, views or
elements.  You could use a block in any of those.

The best example of block usage is the script, css and content blocks as
used by CakePHP itself. All output from the view is written to the content
block.  All css links that are not inline are written to the css block (and
this can be done from the layout, view or any elements included in the
view).  All script links that are not inline are written to the script
block.

One other example I could think of is an element being included in a view
or layout multiple times, with the same data.  If that element was
computationally expensive, you could process once in the view and out to a
block, then display that block in the element.  The processing only gets
done one.  Even better, you could have the element output to the block, if
it is empty, then output the block, Subsequent calls would just output the
block. There are probably alternate solutions using caching as well, but
that would be for when element content is the same across multiple calls to
the site, rather than just calls to the same element within a single view
call.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »