- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 Zend Framework 中,任何人都可以解释部分和占位符之间的区别吗?
据我了解,可以通过使用占位符和部分来呈现特定的模板/容器。
在什么情况下应该使用部分,什么场景是占位符的最佳使用?
最佳答案
这很简单,占位符用于在 View 和布局之间持久化数据,而部分用于在特定 View 中执行特定任务。
请参阅引用资料中的这些摘录。
77.4.1.6. Placeholder Helper: The Placeholder view helper is used to persist content between view scripts and view instances. It also offers some useful features such as aggregating content, capturing view script content for later use, and adding pre- and post-text to content (and custom separators for aggregated content).
77.4.1.5. Partial Helper: The Partial view helper is used to render a specified template within its own variable scope. The primary use is for reusable template fragments with which you do not need to worry about variable name clashes. Additionally, they allow you to specify partial view scripts from specific modules.
<?php
//this is placed in my layout above the html and uses an action helper
//so that a specific action is called, you could also use view helpers or partials
$this->layout()->nav = $this->action('render', 'menu', null,
array('menu' => $this->mainMenuId))
?>
<div id="nav">
//Here the placeholder is called in the layout
<?php echo $this->layout()->nav ?>
</div>
protected function _initMenus() {
$view = $this->getResource('view');
$view->mainMenuId = 4;
$view->adminMenuId = 5;
}
//in the controller
public function preDispatch() {
//add form
$searchForm = new Application_Form_Search();
$searchForm->setAction('/admin/music/update');
$searchForm->query->setAttribs(array('placeholder' => 'Search for Artist',
'size' => 27,
));
$searchForm->search->setLabel('Find an Artist\'s work.');
$searchForm->setDecorators(array(
array('ViewScript', array(
'viewScript' => '_searchForm.phtml'
))
));
//assign form to placeholder
$this->_helper->layout()->search = $searchForm;
}
//in the layout.phtml
<?php echo $this->layout()->search ?>
<article class="search">
<form action="<?php echo $this->element->getAction() ?>"
method="<?php echo $this->element->getMethod() ?>">
<table>
<tr>
<th><?php echo $this->element->query->renderLabel() ?></th>
</tr>
<tr>
<td><?php echo $this->element->query->renderViewHelper() ?></td>
</tr>
<tr>
<td><?php echo $this->element->search ?></td>
</tr>
</table>
</form>
</article>
关于zend-framework - Zend 框架 : what is the difference between partials and placeholders,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9206752/
我的 node.js 应用程序中有一个 Handlebars / mustache 布局文件,如下所示: {{> header}} {{> navbar}} {{{body}}} {{> footer
我的 node.js 应用程序中有一个 Handlebars / mustache 布局文件,如下所示: {{> header}} {{> navbar}} {{{body}}} {{> footer
我有一个主文件,home.html.erb在里面我渲染了大约 15 个部分。这些部分非常小,我想知道是否可以将它们全部放在一个文件中,然后部分地呈现部分部分。 例如,我会制作 _big_partial
在下面的 TypeScript 代码片段中,我需要从一个对象分配给另一个对象,其中它们都是 Partial .在这里,我的直觉是 typescript 应该能够理解正在发生的事情,因为在第 (B) 行
在我的应用程序中,用户通过 AJAX 呈现 _show.html.erb 部分。我现在想要的是在该部分中有一个按钮,单击时将其关闭。 我遇到的问题:如果我将按钮放在部分之外,一切都会正常 - 我可以
我有人造 curry Programming Clojure书。 user=> (defn faux-curry [& args] (apply partial partial args)) #'us
我在尝试实现 AJAX 时遇到了一些困难,其中“link_to” View 被渲染,并且在该 View 中我有另一个 AJAX 调用。 我有菜单侧边栏,其中有这样的内容: "> 在applicatio
我是 asp.net MVC 的新手,请告诉我应该在何处使用局部 View 以及在何处渲染局部 View 。提前致谢 最佳答案 This link might help. Html.RenderPar
我在下拉菜单的 Onchange 事件上更新 DIV 元素。而我正在使用partial 来替换DIV 中的内容。这是我的 ajax 调用: var cach_this = this;
我正在使用 UI-Router AngularJS 的框架,以呈现嵌套的部分。我在渲染父部分及其子部分时遇到问题。这是我的代码: window.app.config(['$stateProvider'
是否存在包含可从Partial中访问的Partial名称的变量?。在_foo.haml中:
我有/views/layouts/_navigation.html.erb,其中生成了部分用户配置文件:
我有一组我想用部分渲染的项目: @items = ['a','b','c'] @items, :partial => 'item' %> 我想用升序对元素进行编号。所以输出应该是: 3: a 2:
尝试使用 .Netcore 制作 Web 应用程序 当我运行该应用程序时,出现此错误。帮我 这不是错误而是警告。但帮我解决 我在下面添加了我的代码 @ViewBag.Title
标题有点令人困惑。 我正在尝试实现一些类似 reddit 的评论系统。这样您就可以查看 Post 并向其添加多态的 Comment 。或者,评论另一条评论。 我的观点是这样的: Post:
我需要编写一个算法来引导机器人穿过“迷宫”(一个有起点、目标、空白区域和不可穿越的空间或“墙壁”的矩形网格)。它可以在任何基本方向(N、NW、W、SW、S、SE、E、NE)上移动,每次移动的成本不变。
?sort指出partial参数可以是NULL或用于部分排序的索引向量。 我试过了: x <- c(1,3,5,2,4,6,7,9,8,10) sort(x) ## [1] 1 2 3 4
MVC4,单击下拉项时,JavaScript 函数在 View 的“脚本”部分中调用。函数对 Controller Action 进行ajax调用,返回Json数据。我需要将一些返回值传递给 Html
我正在使用 Automapper 将数据从 objectA 传输到 objectB classe ObjectA { string Title; string Summary; } cla
我想使用 TortoiseSVN 提交文件的一部分,有什么方法可以做到这一点吗? 我将举一个例子来更清楚地说明我为什么要这样做。 我有一个文件,其中包含一些在构建过程中被替换的定义,如下所示: #de
我是一名优秀的程序员,十分优秀!