Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

For ticket #3315 #925

Closed
wants to merge 1 commit into from

4 participants

@LiquidityC

My first ever contribution. Please respond to malformed commitmsgs or any other stuff that I missed when reading contribution faqs.

Milestone was future and the diff is pretty short. I'm sure I missed alot... I'm just getting started.

@AD7six
Collaborator

The parse error kind of gets in the way. Fixing that there is an E_STRICT error

me: What ticket or problem does this method address?

Edit - I read title :)

@markstory
Owner

Won't this mean that the content between the start() / end() blocks would just be output as normal content? I don't think that is correct either. Instead what you want is a capturing block that is discarded when end() is called. Currently this won't solve the issue, as the block will be output inline.

@LiquidityC
@LiquidityC

I think I did it right now, tested properly and all. Atleast the useless pullrequest got me started. Hope this one is good enough. Please get back to me with any syntax, comment or logic improvements that you need/expect/demand :P

@LiquidityC

I need to a move this to a new branch in my fork so it won't get in the way of my other work. Also allowing me to fiddle around a bit. New pullrequest will be posted shortly. Sorry about all the fiddling around.

@LiquidityC LiquidityC closed this
@ADmad
Collaborator

@LiquidityC Since this is a new feature make sure the new pull request is against the 2.3 branch not master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 29, 2012
  1. @LiquidityC
This page is out of date. Refresh to see the latest.
Showing with 47 additions and 0 deletions.
  1. +1 −0  .gitignore
  2. +11 −0 lib/Cake/View/View.php
  3. +35 −0 lib/Cake/View/ViewBlock.php
View
1  .gitignore
@@ -7,3 +7,4 @@
/dist
.DS_Store
/tags
+*.swp
View
11 lib/Cake/View/View.php
@@ -631,6 +631,17 @@ public function start($name) {
}
/**
+ * Start capturing output for a 'block' if it has no content
+ *
+ * @param string $name The name of the block to capture for.
+ * @return void
+ * @see ViewBlock::startIfEmpty()
+ */
+ public function startIfEmpty($name) {
+ return $this->Blocks->startIfEmpty($name);
+ }
+
+/**
* Append to an existing or new block. Appending to a new
* block will create the block.
*
View
35 lib/Cake/View/ViewBlock.php
@@ -38,6 +38,15 @@ class ViewBlock {
protected $_active = array();
/**
+ * Should the currently captured content be discarded on ViewBlock::end()
+ *
+ * @var boolean
+ * @see ViewBlock::end()
+ * @see ViewBlock::startIfEmpty()
+ */
+ protected $_discardActiveBufferOnEnd = false;
+
+/**
* Start capturing output for a 'block'
*
* Blocks allow you to create slots or blocks of dynamic content in the layout.
@@ -55,12 +64,38 @@ public function start($name) {
}
/**
+ * Start capturing output for a 'block' if it is empty
+ *
+ * Blocks allow you to create slots or blocks of dynamic content in the layout.
+ * view files can implement some or all of a layout's slots.
+ *
+ * You can end capturing blocks using View::end(). Blocks can be output
+ * using View::get();
+ *
+ * @param string $name The name of the block to capture for.
+ * @return void
+ * @see ViewBlock::startIfEmpty()
+ */
+ public function startIfEmpty($name) {
+ if (empty($this->_blocks[$name])) {
+ return $this->start($name);
+ }
+ $this->_discardActiveBufferOnEnd = true;
+ ob_start();
+ }
+
+/**
* End a capturing block. The compliment to ViewBlock::start()
*
* @return void
* @see ViewBlock::start()
*/
public function end() {
+ if ($this->_discardActiveBufferOnEnd) {
+ $this->_discardActiveBufferOnEnd = false;
+ ob_end_clean();
+ return;
+ }
if (!empty($this->_active)) {
$active = end($this->_active);
$content = ob_get_clean();
Something went wrong with that request. Please try again.