Symfony 将模板渲染为字符串
有没有办法在操作中将完全渲染的模板(带或不带布局)作为字符串获取?
即:
public function executeMyAction()
{
$this->variable1 = 'foo';
$this->variable2 = 'bar';
// renders template using assigned variables, partials, layouts, etc. as if it was for output to browser, but assigns html to string
$renderedTemplate = $this->renderTemplateToString();
}
PS我知道这个问题,然而,那里提供的答案并不适合我的目的。链接不起作用,getPartial 获取模板文件而不渲染。
Is there a way to get fully rendered template (with or without layout) as a string, within action?
i.e. something along these lines:
public function executeMyAction()
{
$this->variable1 = 'foo';
$this->variable2 = 'bar';
// renders template using assigned variables, partials, layouts, etc. as if it was for output to browser, but assigns html to string
$renderedTemplate = $this->renderTemplateToString();
}
P.S. I am aware of this question, however the answer provided there isn't that good for my purposes. Links doesn't work and getPartial gets template file without rendering.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你应该尝试
sfController::getPresentationFor()
。you should try
sfController::getPresentationFor()
.