Zend 框架在布局中渲染自定义占位符
我在布局文件中有一些自定义占位符,例如 [Region_Contents] 现在我想在渲染布局时用我的自定义 html 替换这些占位符 就像而不是显示 [Region_Contents] 它可能会显示
Hello this is test block
is there any way to do this?I have some custom place holders in layout file, like [Region_Contents]
now I want to replace these placeholders with my custom html as layout is rendered
like instead of displaying [Region_Contents] it may show
Hello this is test block
is there any way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以为此使用视图过滤器。首先,我们必须像这样实现 Zend_Filter_Interface:
在上面的代码中,$value 包含视图显示之前的字符串表示形式。渲染视图时,ZF 将使用上述函数返回的任何内容。请注意,出于性能原因,我们使用 str_replace 而不是 preg_replace。
接下来,我们需要告诉 ZF 使用我们刚刚制作的过滤器。您可以在引导程序中执行此操作。
欲了解更多信息,请参考以下链接:
Zend 手册
Zend 框架和翻译
You can use view filters for this. First we have to implement the Zend_Filter_Interface like so:
In the code above, $value contains the string representation of the view just before it is displayed. Whatever is returned by the function above will be used by ZF when rendering the view. Note that we're using str_replace over preg_replace for performance reasons.
Next, we need to tell ZF to use the filter we just made. You can do this in the bootstrap.
For more info, please refer to the following links:
Zend Manual
Zend Framework and Translation
如果不需要保留上面描述的相同语法,您可以使用标准
Zend_View
占位符视图助手:http://framework.zend.com/manual/en/zend.view.helpers.html#zend.view.helpers.initial.placeholder希望有所帮助,
If it's not necessary to keep the same syntax you describe above, you might just use the standard
Zend_View
placeholder view helpers: http://framework.zend.com/manual/en/zend.view.helpers.html#zend.view.helpers.initial.placeholderHope that helps,