首页 文章

在流体模板中访问页面记录的MM关系

提问于
浏览
0

我目前正在使用TYPO3构建一个扩展,它扩展了TYPO3核心的 pages 表,由另一个字段扩展 .

我的问题描述:

该字段是我自己的记录的MM关系,包含描述,一些图像等...因为我的扩展名没有't provide its own plugin (it'一般的网站扩展,提供网站模板等等)我必须访问新的字段通过流体模板记录 pages 记录 . 但是,通过访问页面信息数组(使用 <v:page.info field="myfield" ... />{data.myfield} )中的此字段,我只获取引用行的当前计数(pages-record中数据库列的值) .

所以,我的问题是:

  • 如何在流体模板中访问该附加字段的内容,强制TYPO3识别MM跳转到我引用的记录?什么是通常的“TYPO3方式”?

  • 或者我是否必须编写自己的ViewHelper才能获取两个记录之间的引用?

  • 有没有针对此的TypoScript解决方案?

我的TCA(扩展页面)是什么样的:

$temporaryColumns = array(
    'tx_user_myext_myfield' => array(
        /* ... some smaller unimportant TCA settings here ... */
        'config' => array(
            'type' => 'group',
            'internal_type' => 'db',
            'allowed' => 'tx_user_myext_mycustomrow',
            'foreign_table' => 'tx_user_myext_mycustomrow',
            'MM' => 'tx_user_myext_mycustomrow_pages_MM',
            'MM_hasUidField' => 1,
            'multiple' => 1
        )
    )
);

(当然,我将 $temporaryColumns 传递给 addTCAcolumnsaddToAllTCAtypes . 后端功能正常 - 这不是问题 . )

EDIT: 我可以't build a plugin for that, because it'是该网站的一般部分 . (因此,它将在模板中解决 . )只有记录关系应该由用户更改 .

我希望你能帮帮我;非常感谢你对这个问题的任何回复 .

3 回答

  • 1

    最好的方法是扩展/创建页面模型并创建一个插件来显示你的东西 .

    使用TypoScript也可以做到这一点

    myRecords = CONTENT
    myRecords {
      table = tx_user_myext_mycustomrow
      select {
        pidInList = root,-1
        selectFields = tx_user_myext_mycustomrow.*
        join = tx_user_myext_mycustomrow_pages_MM ON tx_user_myext_mycustomrow_pages_MM.uid_local = tx_user_myext_mycustomrow.uid
        where.data = field:_ORIG_uid // field:uid
        where.intval = 1
        where.wrap = tx_user_myext_mycustomrow_pages_MM.uid_foreign=|
        orderBy = tx_user_myext_mycustomrow_pages_MM.sorting_foreign
      }
      renderObj = COA
      renderObj.10 = TEXT
      renderObj.10.field = somefield
      renderObj.10.wrap = <h1>|</h1>
    }
    
    # add myRecords to your fluid variables. I assume that the fluidtemplate is in page.10
    
    page.10.variables.myRecords < myRecords
    

    在流体:

    <f:render.raw>{myRecords}</f:render.raw>
    

    如您所见,TS解决方案几乎与Fluid无关,因为html是在TS中构建的 . 我会建议使用自己的插件 . 将关系字段添加到页面模型并创建一个小插件需要花费很多时间,并且是进一步开发的良好培训 .

  • 2

    使用DatabaseQueryProcessor(如@bschauer所说),可以使用partial来将HTML与Typoscript分开 .

    TypoScript配置:

    page.10.variables.myRecords = CONTENT
    page.10.variables.myRecords {
        table = tx_user_myext_mycustomrow
        select {
            pidInList = root,-1
            selectFields = tx_user_myext_mycustomrow.*
            join = tx_user_myext_mycustomrow_pages_MM ON tx_user_myext_mycustomrow_pages_MM.uid_local = tx_user_myext_mycustomrow.uid
            where.data = field:uid
            where.intval = 1
            where.wrap = tx_user_myext_mycustomrow_pages_MM.uid_foreign=|
            orderBy = tx_user_myext_mycustomrow_pages_MM.sorting_foreign
        }
        renderObj = FLUIDTEMPLATE
        renderObj {
          file = EXT:tx_user_myext/Resources/Private/Partials/MyTemplate.html
          dataProcessing {
            10 = TYPO3\CMS\Frontend\DataProcessing\DatabaseQueryProcessor
            10.references.fieldName = tx_user_myext_myfield
          }
        }
      }
    }
    

    部分MyTemplate.html:

    h1>{data.somefield}</h1>
    

    在您的Fluid模板中:

    <f:format.raw>{myRecords}</f:format.raw>
    
  • 0

    难道你不能使用 DatabaseQueryProcessor 吗?

    示例TypoScript配置:

    10 = TYPO3\CMS\Frontend\DataProcessing\DatabaseQueryProcessor
      10 {
        table = tt_address
        pidInList = 123
        where = company="Acme" AND first_name="Ralph"
        order = RAND()
        as = addresses
        dataProcessing {
          10 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor
          10 {
            references.fieldName = image
          }
        }
      }
    

    https://github.com/TYPO3/TYPO3.CMS/blob/master/typo3/sysext/frontend/Classes/DataProcessing/DatabaseQueryProcessor.php

相关问题