Results 1 to 6 of 6

Thread: [solved] transform html bofore output

  1. #1
    User
    Join Date
    04-05-10.
    Location
    Ukraine, Kiev
    Posts
    47

    Default [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
    Code:
    echo $strBuffer;
    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...
    I forge my wisdom
    Into an arc surrounding all.
    I forge my heartbeat
    To a dome all heavens wide

  2. #2
    User
    Join Date
    07-26-09.
    Posts
    175

    Default Re: $strBuffer = str_replace("a", "b", $strBuffer) don't wor

    Why not use a HOOK?

  3. #3
    User
    Join Date
    04-05-10.
    Location
    Ukraine, Kiev
    Posts
    47

    Default Re: $strBuffer = str_replace("a", "b", $strBuffer) don't wor

    Hm, Thank you, I'll try.
    The outputFrontendTemplate hook is suitable here?
    I forge my wisdom
    Into an arc surrounding all.
    I forge my heartbeat
    To a dome all heavens wide

  4. #4
    User
    Join Date
    04-05-10.
    Location
    Ukraine, Kiev
    Posts
    47

    Default 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?
    I forge my wisdom
    Into an arc surrounding all.
    I forge my heartbeat
    To a dome all heavens wide

  5. #5
    User
    Join Date
    07-26-09.
    Posts
    175

    Default 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.

  6. #6
    User
    Join Date
    04-05-10.
    Location
    Ukraine, Kiev
    Posts
    47

    Default 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
    I forge my wisdom
    Into an arc surrounding all.
    I forge my heartbeat
    To a dome all heavens wide

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •