Search code examples
typo3typoscripttypo3-9.x

How to access complex variables in page typoscript from content element via viewhelper?


I am using cobj_xpath object in my page typoscript as follows.

lib.xpath = XPATH
lib.xpath {
   source = http://docsouth.unc.edu/southlit/poe/poe.xml
   return = string
   resultObj {
      cObjNum = 1
      1.current = 1
   }
}

page.10 = FLUIDTEMPLATE
page.10.variables {
      title < lib.xpath
      title.expression = /TEI.2/text/front/titlePage/docTitle/titlePart

      author < lib.xpath
      author.expression = /TEI.2/text/front/titlePage/docAuthor
}

I can access the 'title' and 'author' variables in page template successfully via {title} and {author} viewhelpers but I cannot access them in the content element level. I cannot even find them in at CE level. Also I have the same problem with other COAs e.g.:

   taleArgument = TEXT
   taleArgument.data = GP:tale

MORE INFO:

I have created the CE via mask extension and configured it to create the required files in /Resources/Mask/ folder. In this folder there is a json file which contains the CE configuration and two folders named Backend and Frontend. Each of these folders contain Layout/Partial/Templates folders. I have inserted the CE created by mask in one of my pages. I manipulate the HTML file in Frontend/Templates as the template file and I can access the fields which I have created in the CE backend properly, so I suppose that my configuration is working well to this end.

  • Typo3 Version: 9.5.19
  • cobj_xpath and cobj_xslt version: 1.9.0

Further Investigations:

To get rid of external extensions, I installed a fresh Typo3. Then I developed a CE in my sitepackage from scratch. My configuration follows:

my_ext/Configuration/TsConfig/Page/Mod/Wizards/NewContentElement.tsconfig

mod.wizards.newContentElement.wizardItems.common {
    elements {
        my_ext_newcontentelement {
            iconIdentifier = folder-open
            title = Registration Example
            description = Create a registration form
            tt_content_defValues {
                CType = my_ext_newcontentelement
            }
        }
    }
    show := addToList(my_ext_newcontentelement)
}

my_ext/Configuration/TCA/Overrides/tt_content.php

<?php
defined('TYPO3_MODE') or die();

call_user_func(function () {

    // Adds the content element to the "Type" dropdown
    \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTcaSelectItem(
        'tt_content',
        'CType',
        [
            'Registration Example',
            'my_ext_newcontentelement',
            'form-checkbox',
        ],
        'textmedia',
        'after'
    );

    // Configure the default backend fields for the content element
    $GLOBALS['TCA']['tt_content']['types']['my_ext_newcontentelement'] = [
        'showitem' => '
        --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:general,
            --palette--;;general,
            --palette--;;headers,
            bodytext;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:bodytext_formlabel,
        --div--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:tabs.appearance,
            --palette--;;frames,
            --palette--;;appearanceLinks,
        --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:language,
            --palette--;;language,
        --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:access,
            --palette--;;hidden,
            --palette--;;access,
        --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:categories,
            categories,
        --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:notes,
            rowDescription,
        --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:extended,
    ',
        'columnsOverrides' => [
            'bodytext' => [
                'config' => [
                    'enableRichtext' => true,
                    'richtextConfiguration' => 'default',
                ],
            ],
        ],
    ];
});

my_ext/Configuration/TypoScript/setup.typoscript

lib.contentElement {
    templateRootPaths.200 = EXT:my_ext/Resources/Private/Templates/ContentElements/
}

tt_content {
    my_ext_newcontentelement =< lib.contentElement
    my_ext_newcontentelement {
        templateName = NewContentElement
    }
}

my_ext/Resources/Private/Templates/ContentElements/NewContentElement.html:

<div>{data.bodytext -> f:format.html()}</div>

I tested my CE after adding one to the backend and it works fine so far.

Then I create a new variable in my_ext/Configuration/TypoScript/setup.typoscript:

page.10.variables {
    test = TEXT
    test.value = test
}

I can see the variable when I add {_all} to my page template:

output of f:debug in page template

but no luck when I try to catch it in my CE template:

output of f:debug in CE template


Solution

  • TLDR:
    each fluid rendering has it's own variables. There are no global fluid-variables.


    It is obvious that you can not access test from your content element as the definition of page.10.variables results in fluid variables used while you are renderend the page-template (page.10).

    In your content element you have an independent rendering with it's own set of variables.

    Meanwhile you often have fluid for some rendering, but each has its own definition and variable set.

    • The whole page has a page fluid rendering.

    • Each plugin has it's own fluid rendering, probably for each action. Although they share a common extension setting which results in some common fluid variables.

    • Each content element has a Fluid rendering, though they might share some definition as the result from the same kind of data (a tt_content record). The kind of CE defines which template is used to start with and there are different renderings.

    Using TYPO9 and ext:bootstrap_package (and ext_fluid_styled_content) you can find:
    The rendering of the CEs is defined below tt_content. with the name of the CE as next key. All definitions are based on lib.dynamicContent


    if you want to access any data independent from context in your fluid you could use typoscript viewhelpers like:

    lib.text = TEXT
    lib.text.value = test
    
    lib.getText = TEXT
    lib.getText.data = GP:text
    

    the calls in fluid:

    <f:cObject typoscriptObjectPath="lib.text" />
    {f:cObject(typoscriptObjectPath:'lib.getText')}