How to get values of fields inside the Section of elements(sc)/Container for elements(co) in templavoila flexible content element (fce)?

Posted: August 3, 2012 by Sankar Vijayakumar in Php, Typo3
Tags: , , , , , ,
get values of fields inside the Section of elements(sc)/Container for elements(co) in templavoila flexible content element

First of all for those who are trying to find a method using typoscript please keep on trying until you’re sure that it’s not possible and for those who got a solution for this question using typoscript please send me or share it somewhere. Before solving this using an userfunction, I had a strong feeling that it’s possible via typoscript (like appending the values to a typoscript variable inside the section and use it outside the section of elements.) and I spend a whole day in search of a typoscript solution but didn’t succeed.
Just by referring the field name it’s possible to get the values of fields in the same level of an FCE. But the same way we can’t take the values of fields inside a “Section of elements” for the fields outside it. For this we can make use of an userfunction as shown below:

  1. Include the php file in the Setup section of TS template:
    includeLibs.fce_values= fileadmin/templates/user_getFlexformFieldValue.php
  2. Code in user_getFlexformFieldValue.php file (the same code that I used in my website – used for fetching the file names added via image field):

    <?php
    class user_getFlexformFieldValue { 
        function main($content, $conf){
            list($table, $uid) = t3lib_div::trimExplode(':',$GLOBALS['TSFE']->currentRecord, 1);
            if ($table=='tt_content') {
                $rec = $GLOBALS['TSFE']->sys_page->getRawRecord($table, $uid);
                $flexXML = $rec['tx_templavoila_flex'];
                $XML = t3lib_div::xml2array($flexXML);
                //$this->cObj->data['field_image_header']; //for getting value fields in the same level.
                $images = "";

                foreach($XML as $key=>$value){
                    if(is_array($value)){
                        foreach($value as $newKey=>$newValue){
                            foreach($newValue as $contentKey=>$contentValue){
                                for($i=1; $i <= count($contentValue[$conf['section_name']]['el']);++$i){
                                    $file_name = $contentValue[$conf['section_name']]['el'][$i][$conf['container_name']]['el'][$conf['field_name']]['vDEF'];

                                    $image = array(
                                        'file' => 'uploads/tx_templavoila/'.$file_name,
                                        'file.' => array (
                                            'maxW' => $conf['imagemaxW'],
                                            'maxH' => $conf['imagemaxH'],
                                            'minW' => $conf['imageminW'],
                                            'minH' => $conf['imageminH']
                                        ),
                                        'stdWrap.'=> array (
                                            'wrap'=> $conf['anchorWrapTag']
                                        ),
                                        'wrap'=> $conf['anchorInnerWrapTag']
                                    );
                                    $images .= $this->cObj->IMAGE($image);
                                }
                            }
                        }
                    }
                }
                return $images;
            }
        }
    }
    ?>

  3. Call the function in typoscript within the TS Setup section of the flexform field outside the “Section of elements”:

    lib.images = USER
    lib.images{
        #function call
        userFunc = user_getFlexformFieldValue->main

        #function parameters
        field_name = field_image_name
        imagemaxW = 309
        imagemaxH = 80
        imageminW =
        imageminH =
        section_name = field_records #Field name of “Section of elements”
        container_name = field_record #Field name of “Container for elements” inside “Section of elements”
        anchorInnerWrapTag =
        anchorWrapTag =
    }

    10 = COA
    10{
        10 < lib.images
    }
    10.wrap = <div class="images">|</div>

How's it? Your comments and suggestions...