首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Access DCE (动态内容元素)使用Typoscript创建字段

Access DCE (动态内容元素)使用Typoscript创建字段
EN

Stack Overflow用户
提问于 2014-08-20 13:06:51
回答 1查看 1.8K关注 0票数 0

在一个项目中,我使用的是TYPO3扩展DCE (动态内容元素)。使用DCE,您可以在不编写扩展的情况下创建自己的动态内容元素。

创建内容对象之后,可以使用流体访问创建的内容元素。

到目前一切尚好。一切都很完美。

现在我的问题是:

我需要使用Typoscript访问DCE元素中的一个变量,如下所示:

代码语言:javascript
运行
复制
10 = TEXT
10 {
    field = referenceCustomer
    wrap = <span class="referenceCustomer">|</span>
}

字段referenceCustomer以前是由DCE创建的。有了液体,我可以用

代码语言:javascript
运行
复制
{field.referenceCustomer}

我真的不知道如何访问生成的字段。

但真正令人困惑的是,我能够访问我在Typoscript中用DCE创建的FAL图像字段。

此代码适用于:

代码语言:javascript
运行
复制
10 = FILES
10 {

    references {
        table = tt_content
        uid.field = uid
        fieldName = referenceImages
    }

    begin = 0
    maxItems = 1

    renderObj = IMAGE
    renderObj {

        file {
            import.data = file:current:uid
            treatIdAsReference = 1
            width = 365c
            height = 125c
        }                                    

        altText.data = file:current:title
        titleText.data = file:current:title
    }

}

也许你能帮我..。我看不见树林里的树木。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-09-01 12:37:47

为了把这个问题写成已解决,我会自己贴出答案。

我制作了一个。UserFunc能够读取FlexForm值。

这是我的解决方案:

Typoscript对象:

代码语言:javascript
运行
复制
includeLibs.FlexformValue =  fileadmin/templates/Utility/UserFunc/FlexformValue.php

5 = USER
5 {
    userFunc = FlexformValue->field
    userFunc {

        uid = TEXT
        uid {
            field = uid
        }

        field = referenceCustomer

    }

}

以及所需的PHP UserFunc:

代码语言:javascript
运行
复制
<?php
/***************************************************************
 *  This script is part of the Typo3 project. The Typo3 project is
 *  free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  The GNU General Public License can be found at
 *  http://www.gnu.org/copyleft/gpl.html.
 *
 *  This script is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  This copyright notice MUST APPEAR in all copies of the script!
 ***************************************************************/

class FlexformValue {

    function field($content, $conf) {

        $conf = $conf['userFunc.'];

        $uid = $this->cObj->stdWrap($conf['uid'], $conf['uid.']);

        $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('pi_flexform', 'tt_content', 'uid = ' . $uid);
        $flexform = \TYPO3\CMS\Core\Utility\GeneralUtility::xml2array(current($GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)));

        $this->temporaryDceProperties = array();
        if(is_array($flexform)) {
            $this->getVDefValues($flexform, $this);
        }

        return $this->temporaryDceProperties[$conf['field']];


    }



    /**
     * Flatten the given array and extract all vDEF values. Result is stored in $this->dceProperties.
     *
     * @param array $array flexform data array
     * @param Object $caller
     * @param null|string $arrayKey
     * @return void
     */
    public function getVDefValues(array $array, $caller = NULL, $arrayKey = NULL) {
        if ($caller === NULL) {
            $caller = $this;
        }
        foreach($array as $key => $value) {
            if ($key === 'vDEF') {
                $caller->temporaryDceProperties[substr($arrayKey, 9)] = $value;
            }
            elseif (is_array($value) && array_key_exists('el', $value)) {
                $propertyName = substr($key, 9);
                $values = array();
                $i = 1;
                if (is_array(current($value))) {
                    foreach (current($value) as $entry) {
                        if (is_array($entry)) {
                            $entry = $entry['container_' . $propertyName]['el'];
                            if (is_array($entry)) {
                                foreach($entry as $k => $v) {
                                    $entry[$k] = $v['vDEF'];
                                }
                                $values[$i++] = array('container_' . $propertyName => $entry);
                            }
                        }
                    }
                }
                $caller->temporaryDceProperties[$propertyName] = $values;
            } elseif (is_array($value)) {
                $this->getVDefValues($value, $caller, $key);
            }
        }
    }

}

我希望这个答案能帮助那些有同样问题的人,然后是我。

问题解决了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25405544

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档