Yii Framework Forum: Hope to add template function with "block" - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Hope to add template function with "block" Rate Topic: -----

#1 User is offline   jerry2801 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 504
  • Joined: 18-November 09

Posted 18 November 2009 - 02:48 AM

like django
<<<
{% block header %}
placeholder
{% endbock %}
>>>

in qeephp
<<<
<?php $this->_block('header'); ?>
placeholder
<?php $this->_endblock(); ?>

is very useful~!~~~~!~~
0

#2 User is offline   sprint 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 21
  • Joined: 15-December 08
  • Location:Ukraine, Dubno

Posted 18 November 2009 - 04:53 AM

you mean this?

in layout:
<?php echo $this->clips['left01']; ?>

in view:
<?php $this->beginClip('left01'); ?>
<?php $this->widget('HomeMenu', array('visible'=>true)); ?>
<?php $this->endClip(); ?>
0

#3 User is offline   puper 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 25
  • Joined: 03-October 09

Posted 18 November 2009 - 05:06 AM

class PBlock extends CWidget
{
    public $blockName = null;
    public $isLayout = false;
    private static $_blocks = array();
    
	public function init()
	{
		ob_start();
		ob_implicit_flush(false);
	}

	public function run()
	{
	    $output = ob_get_clean();
		if (!isset(self::$_blocks[$this->blockName])) {
            self::$_blocks[$this->blockName] = $output;
		}
        if ($this->isLayout) {
            echo self::$_blocks[$this->blockName];
        }
	}
}


in layout:
<?php $this->beginWidget('PBlock', array('blockName' => 'test', 'isLayout' => true));?>
in layout
<?php $this->endWidget();?>


in view:
<?php $this->beginWidget('PBlock', array('blockName' => 'test'));?>
in view
<?php $this->endWidget();?>

0

#4 User is offline   jerry2801 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 504
  • Joined: 18-November 09

Posted 19 November 2009 - 12:38 AM

View Postsprint, on 18 November 2009 - 04:53 AM, said:

you mean this?

in layout:
<?php echo $this->clips['left01']; ?>

in view:
<?php $this->beginClip('left01'); ?>
<?php $this->widget('HomeMenu', array('visible'=>true)); ?>
<?php $this->endClip(); ?>


Thank you! this way is ok~, but if i use block functioin~like:
<?php $this->block('title'); ?> Home page <?php $this->endBlock(); ?> -- in layouts/main.php

and in my view file:
index.php >>>
unused in this file

show.php >>>
<?php $this->block('title'); ?> Show now <?php $this->endBlock(); ?>

when i render above tow view files, get the title:
index.php >>>
Home Page

show.php >>>
Show now

my mean is , block function have "default", or overwrite, evan append
0

#5 User is offline   jerry2801 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 504
  • Joined: 18-November 09

Posted 19 November 2009 - 12:43 AM

View Postpuper, on 18 November 2009 - 05:06 AM, said:

class PBlock extends CWidget
{
    public $blockName = null;
    public $isLayout = false;
    private static $_blocks = array();
    
	public function init()
	{
		ob_start();
		ob_implicit_flush(false);
	}

	public function run()
	{
	    $output = ob_get_clean();
		if (!isset(self::$_blocks[$this->blockName])) {
            self::$_blocks[$this->blockName] = $output;
		}
        if ($this->isLayout) {
            echo self::$_blocks[$this->blockName];
        }
	}
}


in layout:
<?php $this->beginWidget('PBlock', array('blockName' => 'test', 'isLayout' => true));?>
in layout
<?php $this->endWidget();?>


in view:
<?php $this->beginWidget('PBlock', array('blockName' => 'test'));?>
in view
<?php $this->endWidget();?>




This is good way to replace block function~

but, in my opinion, use block in layout file, is the best way~
0

#6 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,879
  • Joined: 04-October 08
  • Location:DC, USA

Posted 19 November 2009 - 12:56 AM

You can use $this->beginClip('test', array('renderClip'=>true))
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users