如何在TYPO3 fluid模板中调用实体方法?

3

我有一个模板,其中有一行是这样的:

<f:format.htmlentitiesDecode>
    {product.features}
</f:format.htmlentitiesDecode>

“features”是“product”数据模型的一个属性。

如果在产品上调用方法,请像这样打印结果:

<f:format.htmlentitiesDecode>
    {product.getStrippedFeatures}
</f:format.htmlentitiesDecode>

但是这会给我返回空内容。

我如何调用产品模型中的方法并打印其输出?

1个回答

6
只需在产品模型中添加以下函数:

如下:

public function getStrippedFeatures()
{
    return your_stripping_method($this->features);
}

Fluid使用带有前缀get的属性,在模板中您只需这样写:

{product.strippedFeatures}

2
Fluid 还会寻找前缀 ishas - Daniel
那部分使用“get”前缀调用属性的代码起了作用 - 谢谢!我曾考虑添加一个视图助手,但现在它已经工作了。ViewHelper: (http://stackoverflow.com/questions/24612883/how-to-access-a-method-and-pass-an-argument-within-the-template) - t3o
1
我太晚了^^ - Euli
早起的鸟儿有虫吃。 :) - Thomas Löffler
需要注意的是,为了使其正常工作,Getter 必须是公共的。 - Euli
1
还值得注意的是:如果您的方法被称为isRoothasStrippedFeatures,那么在fluid中不直观地使用{root}{strippedFeatures}(我认为{isRoot}{hasStrippedFeatures}会是更好的选择)。 - Matmarbon

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接