How can I insert the current page title automatica

2019-03-15 09:37发布

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 just need the bit of typoscript to get the page title out of the database)

I hope that's possible

8条回答
看我几分像从前
2楼-- · 2019-03-15 10:13

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

查看更多
混吃等死
3楼-- · 2019-03-15 10:16

If you want to use this in an fluid page template you can also simple use {data. title} to access the page title.

查看更多
smile是对你的礼貌
4楼-- · 2019-03-15 10:18

I prefer the vhs solution:

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

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

查看更多
三岁会撩人
5楼-- · 2019-03-15 10:25
lib.pagetitle = RECORDS
lib.pagetitle {
    source.data = page:uid
    tables = pages
    conf.pages = TEXT
    conf.pages.field = nav_title
}

To get current page title:

lib.pagetitle = TEXT
lib.pagetitle.field=title

For meta data :

Its very important to place meta after header tag when we are gone through mobile compatible website

In order to prevent quirks mode in IE9 I need to add this lines at the very top of every HTML page:

You can write the whole header by yourself, by adding disableAllHeaderCode = 1 to your typoscript or you can hack it by adding your meta tag directly to the head tag:

 page.headTag = <head><meta http-equiv="X-UA-Compatible" content="IE=edge" />

Place this at your typoscript

 meta.X-UA-Compatible = IE=edge,chrome=1

httpEquivalent: (Since TYPO3 4.7) If set to 1, the http-equiv attribute is used in the meta tag instead of the “name” attribute. Default: 0.

For more information about TYPO3 stuff you may visit my blog

https://jainishsenjaliya.wordpress.com/2013/10/10/put-meta-tag-on-top-of-header-section-in-typo3/

查看更多
ら.Afraid
6楼-- · 2019-03-15 10:33

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

查看更多
啃猪蹄的小仙女
7楼-- · 2019-03-15 10:33
lib.page_title = CONTENT
lib.page_title {

    table = pages

    select {
        where = uid = 2
    }

    renderObj = COA
    renderObj {

        10 = TEXT
        10 {
            field = title
            wrap = <h1 class="page_title">|</h1>
        }

        20 = TEXT
        20 {
            field = subtitle
            stdWrap.required = 1
            stdWrap.wrap = <h5>|</h5>
        }
    }
}

call the lib.page_title where want to render typoscript with this lines

<f:cObject typoscriptObjectPath='lib.page_title' />

I hope this helps !!!

查看更多
登录 后发表回答