html5使用视图块(view blocks)

来源:互联网 发布:百度人工智能有哪些 编辑:程序博客网 时间:2024/05/22 11:56
视图模块取代美元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/layoutecho $this->fetch('navbar');


0 0