Search code examples
typo3typoscripttemplavoila

Set templavoila template with typoscript


Is it possible to set a page's templavoila template with typoscript?


Solution

  • Look how the page is configured by TemplaVoila:

    page = PAGE
    page.typeNum = 0
    page.10 = USER
    page.10.userFunc = tx_templavoila_pi1->main_page
    page.shortcutIcon = {$faviconPath}
    

    They call the main_page function of class tx_templavoila_pi1 via page.userFunc:

    /**
     * Main function for rendering of Page Templates of TemplaVoila
     *
     * @param   string      Standard content input. Ignore.
     * @param   array       TypoScript array for the plugin.
     * @return  string      HTML content for the Page Template elements.
     */
    function main_page($content,$conf)    {
        $this->initVars($conf);
    
            // Current page record which we MIGHT manipulate a little:
        $pageRecord = $GLOBALS['TSFE']->page;
    
            // Find DS and Template in root line IF there is no Data Structure set for the current page:
        if (!$pageRecord['tx_templavoila_ds'])  {
            foreach($GLOBALS['TSFE']->tmpl->rootLine as $pRec)  {
                if ($pageRecord['uid'] != $pRec['uid']) {
                    if ($pRec['tx_templavoila_next_ds'])    {   // If there is a next-level DS:
                        $pageRecord['tx_templavoila_ds'] = $pRec['tx_templavoila_next_ds'];
                        $pageRecord['tx_templavoila_to'] = $pRec['tx_templavoila_next_to'];
                    } elseif ($pRec['tx_templavoila_ds'])   {   // Otherwise try the NORMAL DS:
                        $pageRecord['tx_templavoila_ds'] = $pRec['tx_templavoila_ds'];
                        $pageRecord['tx_templavoila_to'] = $pRec['tx_templavoila_to'];
                    }
                } else break;
            }
        }
    
            // "Show content from this page instead" support. Note: using current DS/TO!
        if ($pageRecord['content_from_pid']) {
            $ds = $pageRecord['tx_templavoila_ds'];
            $to = $pageRecord['tx_templavoila_to'];
            $pageRecord = $GLOBALS['TSFE']->sys_page->getPage($pageRecord['content_from_pid']);
            $pageRecord['tx_templavoila_ds'] = $ds;
            $pageRecord['tx_templavoila_to'] = $to;
        }
    
        return $this->renderElement($pageRecord, 'pages');
    }
    

    This function checks the current page or search trough the rootline (TSFE) for the configured page template. The script does not check any TypoScript settings at all so I suppose thats not supported by TemplaVoila right now.

    It should not be too hard extending this class with a custom function that will check some TypoScript settings.