Search code examples
typo3typoscriptfluidfluid-layout

Typo3 Fluid Templates How to add multiple templates


I have a finished static HTML Template. I need to map it to typo3 so the content is dynamic. I followed following tutorial: https://docs.typo3.org/typo3cms/SitePackageTutorial/FluidTemplates/Index.html

This works perfectly, but now I wonder how I can change the template per site? I made template for each site i.e Gallerie.html, Contact.html and they are linked to the same Layout as Header and Footer is always the same. How do I now tell the page About us to use the Gallerie.html?

My setup.typoscript:

page = PAGE
page {
   typeNum = 0

   // Part 1: Fluid template section
   10 = FLUIDTEMPLATE
   10 {
   templateName = TEXT
   templateName.stdWrap.cObject = CASE
   templateName.stdWrap.cObject {
      key.data = pagelayout

      pagets__default = TEXT
      pagets__default.value = Default

      default = TEXT
      default.value = Default

   }
   templateRootPaths {
      0 = EXT:eventmanagement/Resources/Private/Templates/Page/
      1 = {$page.fluidtemplate.templateRootPath}
   }
   partialRootPaths {
      0 = EXT:eventmanagement/Resources/Private/Partials/Page/
      1 = {$page.fluidtemplate.partialRootPath}
   }
   layoutRootPaths {
      0 = EXT:eventmanagement/Resources/Private/Layouts/Page/
      1 = {$page.fluidtemplate.layoutRootPath}
   }
   dataProcessing {
      10 = TYPO3\CMS\Frontend\DataProcessing\MenuProcessor
      10 {
         levels = 1
         includeSpacer = 1
         as = mainnavigation
      }
   }
}

At the Moment it loads the Default.html Template from eventmanagement/Resources/Private/Templates/Page/ on every page. I created now a second Template called Gallerie.html in eventmanagement/Resources/Private/Templates/Page/ how do I add this now to the page Gallerie in the Backend?


Solution

  • I don't know if it's very useful to have for (nearly) every page another template but in general that's possible. Just consider that in the root-line always that template is used that is defined on the current level or - if not existing - that, that is found first while going up the root-line.

    For every additional template you've to add a section inside this snippet from above:

    templateName.stdWrap.cObject {  
      key.data = pagelayout
    
      pagets__default = TEXT
      pagets__default.value = Default
    
      default = TEXT
      default.value = Default
    
    }
    

    So including the option about us the snippet could look like this:

    templateName.stdWrap.cObject {  
      key.data = pagelayout
    
      pagets__default = TEXT
      pagets__default.value = Default
    
      default = TEXT
      default.value = Default
    
      pagets__aboutus = TEXT
      pagets__aboutus.value = AboutUs
    
      aboutus = TEXT
      aboutus.value = AboutUs
    
    }
    

    Additional you still have to change the TCA probably to include the options in the drop-down-button.