【问题标题】:Access DCE (Dynamic Content Elements) created field with Typoscript使用 Typoscript 访问 DCE(动态内容元素)创建的字段
【发布时间】:2014-10-13 20:38:02
【问题描述】:

在一个项目中,我正在使用 TYPO3 扩展 DCE(动态内容元素)。使用 DCE,您无需编写扩展程序即可创建自己的动态内容元素。

创建内容对象后,您可以使用 FLUID 访问创建的内容元素。

到目前为止一切顺利。一切都很完美。

现在我的问题:

我需要像这样使用 Typoscript 访问 DCE 中的变量:

10 = TEXT
10 {
    field = referenceCustomer
    wrap = <span class="referenceCustomer">|</span>
}

字段referenceCustomer 之前由DCE 创建。使用 FLUID,我可以访问该字段

{field.referenceCustomer}

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

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

此代码有效:

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
    }

}

也许你可以帮助我.. 只见树木不见树林..

【问题讨论】:

    标签: typo3 typoscript fluid


    【解决方案1】:

    为了将此问题标记为已解决,我将自己发布答案。

    我做了一个 PHP Userfunc。 UserFunc 能够读取 FlexForm 值。

    这是我的解决方案:

    Typoscript 对象:

    includeLibs.FlexformValue =  fileadmin/templates/Utility/UserFunc/FlexformValue.php
    
    5 = USER
    5 {
        userFunc = FlexformValue->field
        userFunc {
    
            uid = TEXT
            uid {
                field = uid
            }
    
            field = referenceCustomer
    
        }
    
    }
    

    以及所需的 PHP UserFunc:

    <?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);
                }
            }
        }
    
    }
    

    我希望这个答案能帮助和我有同样问题的人..

    问题解决了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-08-11
      • 2018-03-27
      • 2012-08-30
      • 2011-03-23
      • 2021-05-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多