[solved] transform html bofore output
SOLVED by using a HOOK parseFrontendTemplate.
Thank you, everybody
I need to replace some contents on every page before output it.
At first look it's not a problem.
Opening index.php, adding a line:
Code:
$strBuffer = str_replace("a", "b", $strBuffer);
before
And.... And nothing :shock:
How can i do this?
More shock I've had, when I commented out echo $strBuffer; and page loaded.
Moreover, I've tried to change Copyright notice section (preg_replace) (to see the effect only) — and nothing changed :shock:
Mistery..
Caching is disabled...
Re: $strBuffer = str_replace("a", "b", $strBuffer) don't wor
Re: $strBuffer = str_replace("a", "b", $strBuffer) don't wor
Hm, Thank you, I'll try.
The outputFrontendTemplate hook is suitable here?
Re: $strBuffer = str_replace("a", "b", $strBuffer) don't wor
I can't understand how to implement hooks :(
I am trying to extend Contao's functions at the first time and don't clearly understand, how.
I've added this:
Code:
$GLOBALS['TL_HOOKS']['outputFrontendTemplate'][] = array('myoutput', 'myfunc');
Directly into index.php
Then I've made a file myoutput.php in the root of the site, placed there:
Code:
<?php
public function myfunc($strContent, $strTemplate)
{
$strContent = str_replace("a", "b", $strContent);
return $strContent;
}
?>
and got error
Code:
Fatal error: Could not load class changetags in .../system/functions.php on line 76
Where should I put the file?
Or I'm doing everything wrong?
Re: $strBuffer = str_replace("a", "b", $strBuffer) don't wor
You must define the HOOK within a module. Take a look at /system/modules/news/config/config.php (there you define a hook) and /system/modules/news/News.php (the function). Then create your own files.
Re: $strBuffer = str_replace("a", "b", $strBuffer) don't wor
I've tried to add the hook..
Because I need just one single transform with no backend/frontend modules, I've added it into News module...
Code:
$GLOBALS['TL_HOOKS']['outputFrontendTemplate'][] = array('changetags', 'htmlchange');
And in changetags.php put the function, like mentioned here.
But I've got an error: Parse error: syntax error, unexpected T_PUBLIC in /.../system/modules/news/changetags.php on line 2
Line 2 is:
Code:
public function htmlchange($strContent, $strTemplate) {
I realy don't understand, what is the error? O_O