将变量传递给包含 tx_news 插件的内容对象 [英] Pass a variable to a content object containing a tx_news plugin

查看:16
本文介绍了将变量传递给包含 tx_news 插件的内容对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这与我的问题非常相似 掩码元素计数器在 TYPO3 列中

This is very similar to my question Counter for mask elements in a TYPO3 column

我需要将一个变量(在我的例子中是 cObj:parentRecordNumber 的值,它是列中当前项目的计数器)到模板.

I need to pass a variable (in my case, the value of cObj:parentRecordNumber which is the counter for the current item in it's column) to the template.

在主页模板中:

<f:cObject typoscriptObjectPath="lib.content.pageteasers" />

在打字稿中:

lib.content {
    pageteasers < styles.content.get
    pageteasers {
        select {
            where = colPos=2
            max = 8
        }
        // this passes the variable elementCounter to the fluid template of the rendered mask content element:
        renderObj.mask_teaser {
            variables {
                elementCounter = TEXT
                elementCounter.value = {cObj:parentRecordNumber}
                elementCounter.insertData = 1
            }
        }
        // this should pass the same value to a rendered tx_news plugin: 
        variables {
                elementCounter = TEXT
                elementCounter.value = {cObj:parentRecordNumber}
                elementCounter.insertData = 1
        }
        // it doesn't. what about these trial & error:
        renderObj.list < .variables
        renderObj.plugin.tx_news < .variables
        renderObj.list.20.news_pi1 < .variables
        renderObj.news_pi1 < .variables
        // none of these seem to work either 
    }
 }

然后在渲染的 CE 模板中 (News/List.html)

And then in the rendered CE template (News/List.html)

<f:debug title="" inline="1">{_all}</f:debug>

我没能在这里看到上述变量.将变量从 TS 传递到新闻流体模板的正确方法是什么?

I don't manage to see the above variable in here. What is the correct way to pass the variable from TS to the news fluid template?

PS 另一种尝试是使用 Good Old Register

PS Another try was using the Good Old Register

pageteasers < styles.content.get
pageteasers {
    select {
        where = colPos=2
        max = 8
    }
    append = LOAD_REGISTER
    append {
      elementCounter = TEXT
      elementCounter.value = {cObj:parentRecordNumber}
      elementCounter.insertData = 1
   }
}

在模板中:

{v:variable.register.get(name: 'elementCounter')}

但那是NULL

推荐答案

您通过 register 尝试可以工作.但你必须关心,你在哪里做什么...

Your try via register could work. But you have to care, where you are doing what...

LOAD_REGISTER 属于 string/stdWrap 类型,并且 不是 属于每个定义的 cObject.如果您想使用基于 cObject 的内容,您可以通过 stdWrap 属性声明它(如示例所示):

LOAD_REGISTER is of type string/stdWrap and not a cObject per definition. If you wanna use content based on a cObject, you can declare this via the stdWrap-property (as shown in the examples):

1 = LOAD_REGISTER
1.param.cObject = TEXT
1.param.cObject.stdWrap.data = GP:the_id

所以,在你的情况下,它应该是:

So, in your case it should like:

elementCounter.cObject = TEXT
elementCounter.cObject.data = cObj:parentRecordNumber

在正确的位置追加

您正在尝试将 append 直接用作 pageteasers(它是 styles.content.get 的副本,它是输入 CONTENT.

Appending at the right place

You are trying to use append directly as a property of pageteasers (which is a copy of styles.content.get which is of type CONTENT.

CONTENT 没有 append 属性.此外,您会将寄存器放在整个内容的前面,而不是单个的内容元素.=>它需要作为 renderObj 的一部分,因此按 CE 进行渲染.

CONTENT does not have an append-property. In addition, you would put the register in front of the entire content, not the individual content elements. => It's needed as part of the renderObj, so it's rendered per CE.

CONTENTrenderObj 类型为 CASE,它也没有直接的 stdWrap 属性.但它有一个属性 stdWrapstdWrap-properties...

The renderObj of CONTENT is of type CASE, which also has no stdWrap-properties directly. But it has a property stdWrap with stdWrap-properties...

所以,你可以得到这个片段:

So, you can end up with this snippet:

lib.content {
  pageteasers {   
    renderObj {
      stdWrap {
        append = LOAD_REGISTER
        append {
          elementCounter.cObject = TEXT
          elementCounter.cObject.data = cObj:parentRecordNumber
        }
      }
    }
  }
}

这篇关于将变量传递给包含 tx_news 插件的内容对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆