Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
529 views
in Technique[技术] by (71.8m points)

typo3 - What is the best usage of TypoScript in Fluid templates?

If I want to use TypoScript like menu generation in a Fluid template I have two possible ways:

  • use the TypoScript to fill a variable for the template. doing it like this:

    page.10 = FLUIDTEMPLATE
    page.10 {
        templateName = index.html
        // ... define pathes ...
        variables {
            contentMain < styles.content.get
            mainMenu < temp.mainMenu
            :
        }
    }
    

    and in the template just use the variable:

    <div class="header">
        <div class="logo">{logo->f:format.raw()}</div>
        <div class="main-menu">{mainMenu->f:format.raw()}</div>
    </div> 
    
  • the other way is the usage of the f:cObject ViewHelper to call a part of TypoScript.
    the TypoScript:

    page.10 = FLUIDTEMPLATE
    page.10 {
        templateName = index.html
        // ... define pathes ...
        variables {
            contentMain < styles.content.get
            :
        }
    }
    lib.mainMenu < temp.mainMenu
    

    while the Fluid template looks like this:

    <div class="header">
        <div class="logo">{logo->f:format.raw()}</div>
        <div class="main-menu">
            <f:cObject typoscriptObjectPath="lib.mainMenu />
        </div>
    </div> 
    

so. My question: what are the pros and cons of each way?
Are there differences for the different versions of TYPO3?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I disagree on the opinion of pgampe as there are big differences regarding those 2 approaches!

If you are using variables, those are always rendered, even though those content elements are not used in the frontend. This can have huge side effects which are really hard to tackle. Some examples

  • You have some heavy USER_INT plugins on a page in a column which is not in use (anymore). those will be still called even though they are never shown
  • You are using EXT:news and the feature ExcludeDisplayedNews. If there is a news plugin rendered somehow via variables (but never outputted), a news plugin which is rendered and shown will miss news records

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...