TYPO3 - Overriding & adding meta tags (from tx_metaseo) on detail view of custom extension

时间秒杀一切 提交于 2021-01-28 08:23:29

问题


I have a custom extension and on the detail page of the records I want to seo pimp the profile sites. I'm also using tx_metaseo.

I'm already changing the 'title' tag via the show action like this:

/**
 * action show
 *
 * @param Application $record
 * @return void
 */
public function showAction(Application $record=null) {

        // For the search
        $GLOBALS['TSFE']->indexedDocTitle = $record->getName();     
    }   

}

But since I have tx_metaseo installed ... I'm also getting the generall meta tags. So on the detail page of my extension I would like to override them:

<meta name="DCTERMS.title" content="">
<meta name="description" content="">
<meta name="DCTERMS.description" content="">
<meta name="keywords" content="">
<meta name="DCTERMS.subject" content="">

<meta property="og:title" content="">
<meta property="og:type" content="">
<meta property="og:email" content="">

... in addtion I want to add/set:

<meta property="og:description" content="">

... and I want to have a lange consideration (Default/German/English) ... so I would like to add (for German):

<meta http-equiv="Content-Language" content="de" />
<meta name="Language" CONTENT="Deutsch"/>

How can I do this?

I assume I need to work with Hooks/Signals? https://docs.typo3.org/typo3cms/extensions/metaseo/DeveloperManual/Index.html#signals But how?

Here is a similar discussion: https://github.com/webdevops/TYPO3-metaseo/issues/477

Edit: I tried this to prevent the meta tags created by tx_metaseo

#[globalVar = TSFE:id = 71, GP:tx_metaseo|var = 0]
[globalVar = TSFE:id = 71, GP:tx_metaseo]
    #page.metaseo.meta.og:title >
    #page.metaseo.meta.og:description >
    page.meta.og:title = 
    page.meta.og:description = 
[global]

... or:

[globalVar = TSFE:id = 71]
    plugins.tx_metaseo >
[global]   

回答1:


as you can not override an existing meta value you need to prevent creating of the default meta tags.

One usual way would be a typoscript condition.
You can identify the pages where you show the detail view of your records usually by a URL parameter which gets the uid of the record to be shown.

Regarding news records you could do it like this in a site extension template:

[globalVar = GP:tx_news_pi1|news > 0]
    // set news-specific meta tags
[else]
    // set default meta tags (based just on the pages record)
[global]

or another way:

// somewhere (site_extension or other specific template):
// set default meta tags (based just on the pages record)


// in the static template of your extension:
[globalVar = GP:tx_news_pi1|news > 0]
    // clear default meta tags (if that is possible) 
    page.meta.og:title >
    page.meta.og:site_name >
    page.meta.og:description >
    page.meta.og:image >

    // or deactivate the extension for generating the default meta tags
    // maybe something like
    plugins.tx_metatagsgenarator >

    // finaly: set news-specific meta tags
     :
[global]

The first example can be enhanced for multiple records just by adding more conditions (assuming the detail views of these records are on differnt pages):

[globalVar = GP:tx_news_pi1|news > 0]
    // set news-specific meta tags
[globalVar = GP:tx_myext|myrec_uid > 0]
    // set myext-specific meta tags
[else]
    // set default meta tags (based just on the pages record)
[global]

Using extensions which generate the meta tags whithout option to control it by typoscript would make the whole process very complicated.

Outlook: Handling meta tags will be easier with TYPO3 9.


The easiest manipulation for ext:metaseo looks like the stdWraps mentioned in the manual.
Or use the hooks to manipulate the whole array of all the values the extension is generating.

in the extension manual there are no real hints how to enhance the features of the extension for additional records. as you need to do more than just ethe meta-tags for the detail views: you need to enhace the generated sitemap. Maybe the extension author(s) need some impulse to enhance the manual with the informations how to add meta information for own records.



来源:https://stackoverflow.com/questions/51196631/typo3-overriding-adding-meta-tags-from-tx-metaseo-on-detail-view-of-custom

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!