0

In my general page setup, I define the template as follows: page.10.template.file = fileadmin/template.html

Is there a way to call a MVC ViewHelper in this template? The snippet

{namespace xyz=PATH\TO\MY\ViewHelpers}
<xyz:myhelper argument="abc" />

does not work in the above template, it is surfaced as is.

bernland
  • 688
  • 8
  • 16

1 Answers1

4

It is not 100% clear for me, which cObject you use for your page template. If you would like to use Fluid ViewHelpers in your page template, then I would recommend to use FLUIDTEMPLATE for your page template.

1. FLUIDTEMPLATE

If you use FLUIDTEMPLATE for your page template, then you can use any available ViewHelper (from FLUID or any other ExtBase/Fluid extension) directly in your template (see example below).

TypoScript

page = PAGE
page.10 = FLUIDTEMPLATE
page.10 {
  template = FILE
  template.file = fileadmin/templates/template.html
  partialRootPath = fileadmin/templates/Partials/
  layoutRootPath = fileadmin/templates/Layouts/
  variables {
    content < styles.content.get
    content.select.where = colPos=1
  }
}

Content of file: fileadmin/templates/template.html

{namespace xyz=NAMESPACE\EXTENSION\ViewHelpers}

<f:layout name="Main" />

<f:section name="Content">
  <xyz:myhelper argument="abc" />
  <f:format.html parseFuncTSPath="">{content}</f:format.html>
</f:section>

Content of file: fileadmin/templates/Layouts/Main.html

<f:render section="Content" />

2. TEMPLATE

If you use TEMPLATE (with markers and subparts), then you can't directly use Fluid ViewHelpers in that template. But you could define a marker which renders the FLUID ViewHelper like shown below.

TypoScript

page = PAGE
page.10 = TEMPLATE
page.10 {
  template = FILE
  template.file = fileadmin/templates/template.html
  marks {
    CONTENT < styles.content.get
    VIEWHELPER = FLUIDTEMPLATE
    VIEWHELPER {
      template = FILE
      template.file = fileadmin/templates/viewhelper.html
      partialRootPath = fileadmin/templates/Partials/
      layoutRootPath = fileadmin/templates/Layouts/
    }
  }
  workOnSubpart = DOCUMENT
}

Content of file: fileadmin/templates/template.html

<!--###DOCUMENT### Start-->
###VIEWHELPER###
###CONTENT###
<!--###DOCUMENT### end-->

Content of file: fileadmin/templates/viewhelper.html

{namespace xyz=NAMESPACE\EXTENSION\ViewHelpers}

<f:layout name="Main" />

<f:section name="Content">
  <xyz:myhelper argument="abc" />
</f:section>

Content of file: fileadmin/templates/Layouts/Main.html

<f:render section="Content" />
derhansen
  • 5,585
  • 1
  • 19
  • 29
  • Thank you, I'm using both cObjects for page templates in various projects. Works really well this way! – bernland Jan 09 '15 at 08:00