script

Thursday, May 10, 2012

Mapping template with fluid

TypoScript FLUIDTEMPLATE cObject

Without further ado, here's the page object that utilizes FLUIDTEMPLATE:
page = PAGE
page{
   typeNum = 0   
   10 = FLUIDTEMPLATE
   10 {
      partialRootPath = fileadmin/templates/partials/
      layoutRootPath = fileadmin/templates/layouts/
      file.stdWrap.cObject = CASE
      file.stdWrap.cObject {
         key.data = levelfield:-1, backend_layout_next_level, slide
         key.override.field = backend_layout
         default = TEXT
         default.value = fileadmin/templates/home.html
         2 = TEXT
         2.value = fileadmin/templates/sub.html
      }     
      variables {         
         left < styles.content.get
         left.select.where = colPos=1        
         content < styles.content.get        
         right < styles.content.get
         right.select.where = colPos=2        
      }

   }
}
 
OR SHORTER VERSION
 
page = PAGE
page {

    headerData.11 = HTML
    headerData.11.value = <link href="fileadmin/templates/css/style.css" rel="stylesheet"/>

  10 = FLUIDTEMPLATE
  10 {
            file = fileadmin/templates/fluid.html
            partialRootPath = fileadmin/templates/Partials
            layoutRootPath = fileadmin/templates/Layouts
            variables {
              pageTitle = TEXT
              pageTitle.data = page:title
              left < styles.content.getLeft
              normal < styles.content.get
              right < styles.content.getRight
          }
    }
} 
 
Notice the file selection is based on what the current BE grid is used, so you can define multiple layouts. Of course in order for this to work, you need to define a few backend grids and remember their UIDs because those are used as keys in the CASE cObject above.

Fluid/HTML Template

Next, let's look at the home.html which is used in this example:
<div id="wrap">
  <div id="menu">
    <f:cObject typoscriptObjectPath="lib.navigation" />
  </div>
  <div id="left">
    <f:format.html parseFuncTSPath="lib.parseFunc">{left}</f:format.html>
  </div>
  <div id="content">
    <f:format.html parseFuncTSPath="lib.parseFunc">{content}</f:format.html>
  </div>
  <div id="right">
    <f:format.html parseFuncTSPath="lib.parseFunc">{right}</f:format.html>
  </div>
</div>
As you can see, you can include other TS-defined objects inside your fluidtemplates as well!
This is pretty much all there is to it, the most interesting part of this, compared to TemplaVoila!, is that you can modify your HTML templates without the need to refresh (okay, apart from the 'clear cache' button that you are so used to click) or remap anything.
Also there is no additional tables, wizards or extensions, you use what you already get with the core. Enjoy!

No comments:

Post a Comment