TYPO3 Extbase SEO Meta Tags in Fluid

| | Allgemein, CMS, Web

SEO Optimierung von Extbase Extensions mittels ViewHelper im Fluid Template in TYPO3 – eigentlich ganz einfach.

Oft reicht es nicht, einfach nur die URLs mittels RealURL hübsch und sprechend zu machen und eine 404 Page not found Seite anzulegen. Der nächste Schritt ist also die Optimierung der Meta Keywords, Description und dem Title Tag. In Pibase Extensions konnte man direkt im Code mittels

 $GLOBALS['TSFE']->additionalHeaderData[]

die Meta Daten einstellen, da Extbase allerdings die View vom Controller trennen möchte, sollte man die Meta Daten auch im Fluid einstellen können.

Mit ViewHelpern sind Fluid Templates mindestens genau so mächtig wie die Marker Varianten mit PiBase. Einen SEO ViewHelper zu erstellen, ist auch in wenigen Minuten erledigt. Dadurch lässt sich direkt im Fluid Template einstellen, welche Meta Tags man ausgeben möchte, das könnten Meta Keys, Meta Description oder der Title sein, aber auch Facebook Tags oder bzw. OpenGraph Tags sein.

Zunächst muss die Struktur entsprechend angelegt werden. (Zusätzlich zur normalen Extension Struktur mit ext_emconf.php etc.)

Classes -> ViewHelpers -> FluidseoViewHelper.php

Die eigentliche „Magie“ passiert ausschließlich in der Datei FluidseoViewHelper.php.

PHP Datei: FluidseoViewHelper.php
<?php
namespace TYPO3\Fluidseo\ViewHelpers;
/***************************************************************
 * Copyright notice
 *
 * (c) 2016 Marc Horst <info@marc-horst.de>
 * All rights reserved
 *
 * This script is part of the TYPO3 project. The TYPO3 project is
 * free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * The GNU General Public License can be found at
 * http://www.gnu.org/copyleft/gpl.html.
 *
 * This script is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * This copyright notice MUST APPEAR in all copies of the script!
 * Example
 * {namespace m=TYPO3\Fluidseo\ViewHelpers}
 *
 * @package TYPO3
 * @subpackage Fluidseo
 * @version
 */
class FluidseoViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
 /**
 * Simple Fluid SEO Viewhelper
 * @param string $tag
 */
 public function render($tag) {
 switch ($tag) {
 case 'title':
 $GLOBALS['TSFE']->page['title'] = trim($this->renderChildren());
 break;
 case 'og:title':
 $GLOBALS['TSFE']->additionalHeaderData[] = '<meta property="og:title" content="'.htmlspecialchars(trim($this->renderChildren())).'"/>';
 break;
 case 'og:type':
 $GLOBALS['TSFE']->additionalHeaderData[] = '<meta property="og:type" content="'.htmlspecialchars(trim($this->renderChildren())).'"/>';
 break;
 case 'og:url':
 $GLOBALS['TSFE']->additionalHeaderData[] = '<meta property="og:url" content="'.htmlspecialchars(trim($this->renderChildren())).'"/>';
 break;
 case 'og:image':
 $GLOBALS['TSFE']->additionalHeaderData[] = '<meta property="og:image" content="'.htmlspecialchars(trim($this->renderChildren())).'"/>';
 break;
 case 'og:description':
 $GLOBALS['TSFE']->additionalHeaderData[] = '<meta property="og:description" content="'.htmlspecialchars(trim($this->renderChildren())).'"/>';
 break;
 case 'fb:app_id':
 $GLOBALS['TSFE']->additionalHeaderData[] = '<meta property="fb:app_id" content="'.htmlspecialchars(trim($this->renderChildren())).'"/>';
 break;
 case 'og:site_name':
 $GLOBALS['TSFE']->additionalHeaderData[] = '<meta property="og:site_name" content="'.htmlspecialchars(trim($this->renderChildren())).'"/>';
 break;
 default:
 $GLOBALS['TSFE']->additionalHeaderData[] = '<meta name="'.$tag.'" content="'.htmlspecialchars(trim($this->renderChildren())).'"/>';
 break;
 } 
 }
 
}
?>

Zusätzlich zu den normalen Tags description, title etc. habe ich noch die typischen Facebook und OpenGraph Tags hinzugefügt.

Wenn die Extension installiert ist und der Cache geleert ist, wird der ViewHelper muss der ViewHelper nur noch eingebunden werden

{namespace m=TYPO3\Fluidseo\ViewHelpers}

Und kann dann folgendermaßen genutzt werden

Der Inhalt des Tags wird nur im Header ausgegeben.
<m:fluidseo tag="description or other">
Tagcontent
</m:fluidseo>

Neueste Beiträge

Introducing a simple Docker Compose setup for HMS MQTT Publisher

Update: I am using this „much easier“ integration now: https://github.com/suaveolent/ha-hoymiles-wifi[GitHub, External]

I’ve been tinkering with my home automation setup recently, specifically integrating HMS-XXXXW-2T series micro-inverters with my system. The hms-mqtt-publisher[GitHub, External] is a neat tool that does just that by fetching telemetry info from these inverters and publishing it to an MQTT broker. The catch? It typically requires compiling from source with Cargo, Rust’s package manager.


Weiter >>

Effortlessly Backing Up Paperless-ngx with Cloudflare, rclone, and Docker

In the digital age, data backup is a non-negotiable part of managing any document management system. For those of us relying on the efficiency and organizational prowess of Paperless-ngx, ensuring our data is safe and recoverable is paramount. I’ve devised a seamless backup solution that utilizes the power of Cloudflare’s rclone and Docker, guaranteeing peace of mind and data security. Here’s a detailed look into my approach, which is applicable not just for Paperless-ngx but for any data stored on R2 storage. (https://www.cloudflare.com/developer-platform/r2/, Pricing: https://www.cloudflare.com/plans/developer-platform/ (10GB/Month for free))


Weiter >>

Ein Leitfaden für Senioren: Günstige Smartphones und Handys für Senioren bis 170 Euro

Mit über 80 Jahren beschlossen mein Opa, sich der digitalen Welt anzuschließen. Meine Oma nutzt bereits ein Xiaomi-Handy und schätzt dessen Einfachheit. Nun möchte mein Opa auch ein Mobiltelefon, das eine gute Kamera hat und einfach zu bedienen ist, aber dennoch WhatsApp und andere Funktionen unterstützt – und besonders wichtig: Kein Senioren Handy

Kurzversion: Am Ende ist es das Xiaomi Redmi 12 geworden, was zu dem Zeitpunkt bei Amazon für 149,90 Euro verfügbar war*


Weiter >>