简体   繁体   English

如何将值从流体页面模板传递到ext:mask内容元素模板?

[英]How to pass a value from a fluid page template into a ext:mask content element template?

In TYPO3 7 LTS with ext:mask, I would like to pass a value from my page template into the FLUIDTEMPLATE that is rendered via the mask extension. 在带有ext:mask的TYPO3 7 LTS中,我想将页面模板中的值传递给通过mask扩展名呈现的FLUIDTEMPLATE。

An example for what I'm trying to achieve: 我要实现的示例:

The content element has content that describes a car: A Volvo, 4WD... content元素具有描述汽车的内容:Volvo,4WD ...

In the page template, I want to display that "car" in different colors. 在页面模板中,我想以不同的颜色显示“汽车”。 So the page template would be able to command: "get the first car, and show it in green. Then the second car and show it in yellow". 因此,页面模板将能够命令:“获得第一辆汽车,并以绿色显示。然后,第二辆汽车,并以黄色显示”。 (and no, it's got nothing to do with css..) (不,与css无关。)

If this has to be done once onan entire page, I can use 如果必须在整个页面上完成一次,我可以使用

`tt_content.default.mask_car.settings.color = green`

Or (for the record) if the purpose of that variable would be to modify the presentation, I could use: 或者(出于记录目的)如果该变量的目的是修改表示形式,则可以使用:

`tt_content.default.mask_car.settings.file = path/to/Mask/Content/Templates/car_green.html`

But if there are several instances of the same content element on the page, that approach is no good. 但是,如果页面上有多个相同内容元素的实例,那么这种方法就不好了。

How to pass different values into different instances of the same CE on a page? 如何将不同的值传递到页面上同一CE的不同实例中?

you could add following TypoScript: 您可以添加以下TypoScript:

lib.set_register = LOAD_REGISTER
lib.set_register.color = TEXT
lib.set_register.color.current = 1

lib.get_register.color = TEXT
lib.get_register.color.data = register:color

lib.mask_car < styles.content.get
lib.mask_car.select.where = colPos=123

And within your page template you set the color with Fluid 在页面模板中,您可以使用Fluid设置颜色

<f:cObject typoscriptObjectPath="lib.set_register.color" data="green"/>

Get your content elements with Fluid 使用Fluid获取您的内容元素

<f:cObject typoscriptObjectPath="lib.mask_car"/>

And switch the content element's out put within your mask template with Fluid 并使用Fluid将内容元素的输出切换到蒙版模板中

<f:if condition="{f:cObject(typoscriptObjectPath: 'lib.get_register.color')} == 'green'">
    <f:then>
        green
    </f:then>
    <f:else>
        not green
    </f:else>
</f:if>

I hope this helps you to solve your problem. 我希望这可以帮助您解决问题。

I had a similar problem: A collection of mask content elements; 我有一个类似的问题:蒙版内容元素的集合; two different renderings of the same element on the same page: 同一页面上同一元素的两个不同渲染:

  • One random mask-ce rendered as teaser, linking to the detail on the bottom of the page 一个随机的遮罩层渲染为预告片,链接到页面底部的详细信息
  • A list of all mask ce's rendered as list-items (detail) 呈现为列表项的所有蒙版CE的列表(详细信息)

    My solution: 我的解决方案:

Rendering of the random teaser: 随机预告片的渲染:

lib.qa_random_teaser_community < styles.content.get
lib.qa_random_teaser_community.select{
  where = colPos=12
  pidInList = {$pidCommunityQAStorage}
  max = 1
  orderBy = rand()
}

Rendering of the detail list: 详细列表的呈现:

lib.qa_list_community < styles.content.get
lib.qa_list_community{
  renderObj < tt_content
  renderObj.default.mask_qa_community.settings.renderListItems = 1
  select {
    where = colPos=12
    pidInList = {$pidCommunityQAStorage}
  }
}

I copy the tt_content to renderObj, then I can modify it, adding a dedicated setting for the mask element just for this content rendering: 我将tt_content复制到renderObj,然后可以对其进行修改,为该内容渲染添加mask元素的专用设置:

renderObj.default.mask_qa_community.settings.renderListItems = 1

In the mask template, I just have to check for the setting and trigger the appropriate rendering: 在遮罩模板中,我只需要检查设置并触发适当的渲染即可:

<f:if condition="{settings.renderListItems}">
  <f:then>
    <f:render section="qa-detail" arguments="{data:data}"/>
  </f:then>
  <f:else>
    <f:render section="qa-teaser" arguments="{data:data}"/>
  </f:else>
</f:if>

Another approach would be to select a dedicated fluid-template instead of just feeding a setting: 另一种方法是选择专用的流体模板,而不是仅输入设置:

renderObj.default.mask_qa_community.settings.file = .......

In Mask 3.0.1 with TYPO3 8... 在具有TYPO3 8的Mask 3.0.1中...

renderObj.mask_qa_community.settings.file = .......

Hope it's useful for someone else. 希望对其他人有用。

I'm revisiting this question, in TYPO3 9 with mask 4.x, this works: 我正在使用面罩4.x在TYPO3 9中重新审视此问题:

lib.my_content_element {
  renderObj.mask_content_text.settings.test = 123
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM