html5使用视图块(view blocks)

视图模块取代美元scripts_for_layout并提供一个灵活的API,允许您定义槽或块在你的看法/布局,将定义的其他地方。例如块理想实现诸如侧边栏,或地区负荷资产/底部的布局。块可以被定义在两个方面。捕获块,或通过直接任务。start(),append()和end()方法允许附加到处理捕获块:

// create the sidebar block.
$this->start('sidebar');
echo $this->element('sidebar/recent_topics');
echo $this->element('sidebar/recent_comments');
$this->end();


// Append into the sidebar later on.
$this->append('sidebar');
echo $this->element('sidebar/popular_topics');
$this->end();


你也可以附加到一块多次使用start(),assign()可以用来清晰或覆盖一块在任何时间:

// Clear the previous content from the sidebar block.
$this->assign('sidebar', '');


现有前置内容块prepend():

// Prepend to sidebar
$this->prepend('sidebar', 'this content goes on top of sidebar');



startIfEmpty()方法可以用来开始一块只有在其空或未定义的。如果块已经存在捕获的内容会被丢弃。这是有用的,当你想有条件地为块定义默认内容应该不存在:

// In a view file.
// Create a navbar block
$this->startIfEmpty('navbar');
echo $this->element('navbar');
echo $this->element('notifications');
$this->end();

// In a parent view/layout
<?php $this->startIfEmpty('navbar'); ?>
<p>If the block is not defined by now - show this instead</p>
<?php $this->end(); ?>

// Somewhere later in the parent view/layout
echo $this->fetch('navbar');


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值