【问题标题】:Call ViewHelper from outside Fluid template从 Fluid 模板外部调用 ViewHelper
【发布时间】:2015-01-04 09:58:59
【问题描述】:

在我的常规页面设置中,我将模板定义如下:page.10.template.file = fileadmin/template.html

有没有办法在这个模板中调用 MVC ViewHelper? sn-p

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

在上面的模板中不起作用,它按原样浮出水面。

【问题讨论】:

    标签: typo3 viewhelper


    【解决方案1】:

    我还不是 100% 清楚您将哪个 cObject 用于您的页面模板。如果您想在您的页面模板中使用 Fluid ViewHelpers,那么我建议您使用 FLUIDTEMPLATE 作为您的页面模板。

    1.流体模板

    如果您使用FLUIDTEMPLATE 作为您的页面模板,那么您可以直接在您的模板中使用任何可用的 ViewHelper(来自 FLUID 或任何其他 ExtBase/Fluid 扩展)(参见下面的示例)。

    打字稿

    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
      }
    }
    

    文件内容: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>
    

    文件内容:fileadmin/templates/Layouts/Main.html

    <f:render section="Content" />
    

    2。模板

    如果您使用TEMPLATE(带有标记和子部分),则不能在该模板中直接使用 Fluid ViewHelpers。但是您可以定义一个标记来呈现 FLUID ViewHelper,如下所示。

    打字稿

    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
    }
    

    文件内容:fileadmin/templates/template.html

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

    文件内容:fileadmin/templates/viewhelper.html

    {namespace xyz=NAMESPACE\EXTENSION\ViewHelpers}
    
    <f:layout name="Main" />
    
    <f:section name="Content">
      <xyz:myhelper argument="abc" />
    </f:section>
    

    文件内容:fileadmin/templates/Layouts/Main.html

    <f:render section="Content" />
    

    【讨论】:

    • 谢谢,我在各种项目中都将这两种 cObjects 用于页面模板。这种方式效果很好!
    猜你喜欢
    • 2012-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-06
    • 1970-01-01
    • 2017-01-10
    • 1970-01-01
    相关资源
    最近更新 更多