How can I insert the current page title automatically into a TYPO3 template?

后端 未结 8 858
终归单人心
终归单人心 2021-02-05 17:08

actually the title is the whole question.

I just want to modify the template so that the current page title is automatically shown (i\'m working with html templates so I

相关标签:
8条回答
  • 2021-02-05 17:22

    The question is quite old but I still want to add something I never read here.

    TYPO3 offers many things concerning the header, and it's right that it's also possible to render it completely individual. Nevertheless all the nice options of TYPO3 are more or less disabled by the individual solution.

    So first the direct answer on the question:
    The default page title can be overridden like this

    config.pageTitle.stdWrap.override.cObject < lib.pagetitle
    

    If several page types are defined and the title shall be set individually for each type, the configuration can be noted inside the page-definitions:

    page = PAGE
    page {
        typeNum = 0
        config.pageTitle.stdWrap.override.cObject < lib.pagetitle_1
        ...
    }
    
    anotherPage = PAGE
    anotherPage {
        typeNum = 1
        config.pageTitle.stdWrap.override.cObject < lib.pagetitle_2
        ...
    }
    

    Below still a lib.pagetitle which makes a little bit more than only using title or subtitle - it uses news-title if the extension is used on a page:

    lib.pagetitle = COA
    lib.pagetitle {
    
      10 = TEXT
      10 {
        // subtitle: used as field for title tag
        value.field = subtitle // title
        if.isFalse.data = GP:tx_news_pi1|news
      }
    
      20 = RECORDS
      20 {
            if.isTrue.data = GP:tx_news_pi1|news
            dontCheckPid = 1
            tables = tx_news_domain_model_news
            source.data = GP:tx_news_pi1|news
            source.intval = 1
            conf.tx_news_domain_model_news = TEXT
            conf.tx_news_domain_model_news {
                field = title
                htmlSpecialChars = 1
            }
        }
     }
    

    Now still some background why I think some individual header might not be the best solution:

    • TYPO3 usually adds several details to the header, that are useful and it's not required to combine those things individually new.
    • Scripts and stylesheets are organized and can be even by TypoScript compressed and merged. If some syntax is followed it even takes care that a library like jquery is only included once.
    • TYPO3 has many functions in TypoScript where everything can be defined related to the header and also it can be decided if scripts shall be perhaps never be included at all in the header but instead in the bottom of the page-source.
    • Metatags can be defined (and overridden by extensions or sub-templates)

    Implementing this whole logic manually again in an own template in my opinion is not useful and I think headers should be only disabled for special page-types like AJAX or dynamic PDF-files. This is the primary reason that I consider that option as useful.

    Her still the current link for the most recent documentation about the config-options in TypoScript (anchor pagetitle): https://docs.typo3.org/typo3cms/TyposcriptReference/Setup/Config/Index.html#pagetitle

    0 讨论(0)
  • 2021-02-05 17:25

    You can current page title by following typoscript:

    lib.pagetitle = TEXT
    lib.pagetitle.data = page : title
    

    and then use this object to your page using typoscriptObjectPath like following way:

    <f:cObject typoscriptObjectPath="lib.pagetitle"/>
    
    0 讨论(0)
  • 2021-02-05 17:25

    If you want to use a fluid only solution, install the VHS extension and you can output the page title without using any TypoScript at all like this:

    Tag Example:

    <v:page.header.title title="NULL" whitespaceString="' '" setIndexedDocTitle="1">
      <!-- tag content - may be ignored! -->
    </v:page.header.title>
    

    Inline Example:

    {v:page.header.title(title: 'NULL', whitespaceString: '' '', setIndexedDocTitle: 1)}

    0 讨论(0)
  • 2021-02-05 17:28

    It is. It's pretty simple to do. I'll assume you're using TemplaVoilà, because if you're not, you should be :-D

    Start off by putting some HTML in your template with a dummy page title. Give it an ID attribute so it's easy to map. Like:

    <h1 id="page-title">Page Title Here</h1>
    

    Next, go into TemplaVoilà and map that <h1> element to the content type "TypoScript Object Path". When it prompts you for the object path, you can put in anything you want -- convention is that dynamic content is added in the "lib" namespace, so let's call it lib.pagetitle. When it asks you if you want to map this to "INNER" or "OUTER", choose "INNER" -- that will mean you're just mapping the space BETWEEN the <h1>...</h1> tags. ("OUTER" means you're replacing the whole element, including the tags, which we don't want here because we want this to stay an H1.) Save your template mapping.

    Now go into your site's TypoScript template. Here you're going to insert the logic that fills in that space we just mapped with actual content. To insert the page title is a matter of a couple of lines of TypoScript:

    lib.pagetitle = TEXT
    lib.pagetitle.data = page : title
    

    What this says is "take the space in the template that I mapped to lib.pagetitle. Create a content object in that space of type TEXT. Then fill that content object with the title of the page."

    Save your TypoScript template. Now you're done!

    This probably sounds complicated at first glance, and it is, but the nice thing about this system is that it's amazingly flexible. Inserting text dynamically is just the beginning. The TypoScript Reference (a.k.a. the "TSRef") has all the details -- look up "getText" to get a flavor, that's the function that makes the "page : title" call in your TypoScript template drop in the page title.

    TSRef is your friend. I keep a printed copy of it at my desk -- if you want to make TYPO3 sing, it is your songbook.

    0 讨论(0)
  • 2021-02-05 17:28

    I prefer the vhs solution:

    {v:page.info(field:'title')}
    

    https://fluidtypo3.org/viewhelpers/vhs/master/Page/InfoViewHelper.html

    0 讨论(0)
  • 2021-02-05 17:31

    If you want to use this in a fluid page template, you can also simple use:

    {data.title}
    

    to access the page title.

    0 讨论(0)
提交回复
热议问题