传递模板将结果渲染到另一个方法(passing template render result to another method)

编程入门 行业动态 更新时间:2024-10-27 02:18:37
传递模板将结果渲染到另一个方法(passing template render result to another method)

我正在尝试将$this->render()结果分配给一个方法(此方法呈现谷歌地图的infoWindow / baloon)。

我正在使用这样的方法来创建这个infoWindow:

$infoWindow->setContent(<here goes the template>);

但是像这样传递:

$infoWindow->setContent($this->render('WmapFrontBundle:Place:infoWindow.html.twig'));

根本不工作。 将模板分配给变量或将其内容传递给方法的正确方法是什么?

i'm trying to assign $this->render() result to a method (this method renders google map's infoWindow/baloon).

I'm using method like this to create this infoWindow:

$infoWindow->setContent(<here goes the template>);

but passing it like this:

$infoWindow->setContent($this->render('WmapFrontBundle:Place:infoWindow.html.twig'));

don't work at all. What's the proper way to assign template to a variable or pass it's content to a method ?

最满意答案

使用renderView() ,它只返回渲染的模板。

render()返回一个Response对象(带有渲染模板,头文件等)。

Use renderView(), it returns the rendered template only.

render() returns a Response object (with the rendered template, headers, etc).

更多推荐

本文发布于:2023-04-29 12:42:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1336262.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模板   方法   passing   template   result

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!