TYPO3 - hook / signal after page rendered - typo3

Is there any hook/signal or anything else so that I can modify final HTML code of frontend page rendered by TYPO3?
My use case is:
I want to apply some regex and logging for links that are displayed across whole website - no matter if the link is rendered via tt_content bodytext (typolink or hardcoded) or by frontend plugin or comes via typoscript or possibly any other way.

The PAGE object in TypoScript has stdWrap, so you can use userFunc there.
page = PAGE
page {
...
stdWrap.userFunc = Your\NameSpace\YourClass->doStuff
}

If you prefer to use real hooks instead of stdWrap you can look at the function generatePage_postProcessing which has three hooks. In the CoreApi Documentation you can find the way how to use hooks.
In your ext_localconf.php you can define your hook usage. As example:
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['contentPostProc-all'][] = My\NameSpace\Hooks\PageGenerateHooks::class . '->contentPostProcAll'
Now in your hook class you can modify the content:
<?php
namespace My\Namespace\Hooks;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
class PageGenerateHooks
{
/*
* \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController $pObj
*/
public function contentPostProcAll(TypoScriptFrontendController $pObj)
{
$pObj->content = preg_replace('#mySearch#i','myTerm', $pObj->content;
}
}

Related

Typo3 9.5 UrlLinkHandler

I'm trying to use the UrlLinkHandler in Typo3 9.5. So far I've configured my Backend with TCEMain.
TCEMAIN.linkHandler.youtube {
handler = TYPO3\CMS\Recordlist\LinkHandler\UrlLinkHandler
label = Youtube
}
This works fine so far and I can add links within the RTE.
For rendering the Link in the frontend my Typoscript looks like this:
config {
recordLinks.youtube {
typolink {
wrap = test|test
}
}
}
But the frontend just shows a regular rendered anchor tag like Link.
Any hints what I'm doing wrong?
Oehm, you're mixing up different things... You register a new UrlLinkHandler for BE, but your recordLinks-block for FE is a part of the RecordLinkHandler.
If you want to have a link-type formatted in a special (like you described on typo3.net), then an own LinkHandler could be a solution.

Add a static template to my typo3 extension

I have created an extension with sitepackagebuilder.com and the idea is just to write some static html.
I know that when you have a controller you can call the templates by following the convention names. But what if you don't have a controller? What I need, at least for now, is just to install the extension, add the plugin into a page and get some static content in that page.
I can imagine that this is set in a typoscript file but I'm quite noob with all the typoscript thing.
I'm getting this error:
'No Content Object definition found at TypoScript object path "tt_content.list.20.heboorganigram_organigram"'
Until I define that object in my typoscript file. I have tried this.
tt_content.list.20.heboorganigram_organigram = PAGE
tt_content.list.20.heboorganigram_organigram.10 = TEMPLATE //(or FLUIDTEMPLATE same result)
tt_content.list.20.heboorganigram_organigram.10.template = FILE
tt_content.list.20.heboorganigram_organigram.10.template.file = fileadmin/Organigram.html
And then I don't get an error but I also don't get the content from my Organigram.html, this is just trying stuffs, I actually don't know if this is what I need to do.
Before creating new Content Elements you first have to create the Page Template, for that have a look at the sitepackage tutorial https://docs.typo3.org/m/typo3/tutorial-sitepackage/master/en-us/FluidTemplates/Index.html
If you already got the page template, have a look at https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/ContentElements/AddingYourOwnContentElements.html
Provided you already did the steps above, for getting the frontend output you are interested in the step Configure the frontend rendering
So the TypoScript should look something like this:
lib.contentElement {
templateRootPaths.200 = EXT:heboorganigram/Resources/Private/Templates/
}
tt_content {
examples_newcontentelement =< lib.contentElement
examples_newcontentelement {
templateName = NewContentElement
}
}
Then you need to place your Organigram.html file in the Templates Folder in inside the sitepackage.

No default link classes in typo3 8 anymore?

In V7 all internal/external/download links got an additional class by default, like 'internal-link' or 'download'.
Looks like in V8 with the new CKEditor this feature is gone.
Is there a way to reimplement it via typoScript or some kind of yaml RTE config?
An automatic solution, not the solution where the user have to pick a custom style, thats our current workaround.
If these classes should be applied automatically to specific link types without enabling the editors to change those classes, you should go for TypoScript parseFunc:
https://docs.typo3.org/typo3cms/TyposcriptReference/Functions/Parsefunc.html?highlight=parsefunc
Especially makeLinks, tags and typolink should be useful here:
https://docs.typo3.org/typo3cms/TyposcriptReference/Functions/Makelinks.html#makelinks
https://docs.typo3.org/typo3cms/TyposcriptReference/Functions/Tags.html#tags
https://docs.typo3.org/typo3cms/TyposcriptReference/Functions/Typolink.html#atagparams
For example you would assign a specific class to an external http link automatically created by makelink like this:
parseFunc {
makelinks = 1
makelinks {
http {
keep = path
extTarget = _blank
ATagParams = class="external-link"
}
}
}

TYPO3 Extension output altered by TYPO3?

TYPO3 seems to alter the output of my Frontend extension.
Simple Testcase:
function main($content, $conf)
{
$this->conf = $conf;
$this->pi_setPiVarDefaults();
$this->pi_loadLL();
return 'test';
}
When I call a page with this extension in the frontend i get:
test
Basically it prepends the path I used to access the page to the anchor link.
What could be responsible for this behaviour? RealURL?
How can I disable it?
You probably have somwhere in your TS template (in Setup) enabled prefixing:
config.prefixLocalAnchors = all
Note, that if you have set config.baseURL=http://some.tld/ and enabled RealURL this is required, otherwise all anchor links will be redirected to the main page:
http://some.tld/#test
instead of
http://some.tld/pagename/sub/other-sub#test

Zend framework rendering custom place holders in layout

I have some custom place holders in layout file, like [Region_Contents]
now I want to replace these placeholders with my custom html as layout is rendered
like instead of displaying [Region_Contents] it may show Hello this is test block
is there any way to do this?
You can use view filters for this. First we have to implement the Zend_Filter_Interface like so:
class My_View_Filter_PlaceholderReplacer implements Zend_Filter_Interface
{
public function filter($value)
{
return str_replace('[Region_Contents]', 'Hello this is test block', $value);
}
}
In the code above, $value contains the string representation of the view just before it is displayed. Whatever is returned by the function above will be used by ZF when rendering the view. Note that we're using str_replace over preg_replace for performance reasons.
Next, we need to tell ZF to use the filter we just made. You can do this in the bootstrap.
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initViewSettings()
{
$this->bootstrap('view');
$view = $this->getResource('view');
$view->addFilterPath('My/View/Filter', 'My_View_Filter');
$view->setFilter('PlaceholderReplacer');
...
}
...
}
For more info, please refer to the following links:
Zend Manual
Zend Framework and Translation
If it's not necessary to keep the same syntax you describe above, you might just use the standard Zend_View placeholder view helpers: http://framework.zend.com/manual/en/zend.view.helpers.html#zend.view.helpers.initial.placeholder
Hope that helps,