We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33337
    • 3,975 Posts
    Author: Jason Coward (OpenGeek)

    Description: This plugin replaces a phrase with a chunk. Phrase and Chunk both are editable in the plugin code.

    /**
     * ChunkReplace Plugin 
     * Written By Jason Coward (OpenGeek) - June 22, 2006
     *
     * Version 1.0
     *
     * Events: OnWebPagePrerender
     *
     * Usage: Please setup "phrase_to_replace" and "myChunk" to your requirments.
     *
     *
     */
    
    $e= & $modx->Event;
    switch ($e->name) {
        case "OnWebPagePrerender" : //mo register only for backend
            $modx->documentOutput= str_replace('phrase_to_replace', $modx->getChunk('myChunk'), $modx->documentOutput);
            break;
    
        default :
           return; // stop here - this is very important. 
            break;
    }
    
      Zaigham R - MODX Professional | Skype | Email | Twitter

      Digging the interwebs for #MODX gems and bringing it to you. modx.link
      • 6726
      • 7,075 Posts
      I am not sure how I will use that but I’ll keep this in mind...

      Sample use ?
        .: COO - Commerce Guys - Community Driven Innovation :.


        MODx est l'outil id
        • 33337
        • 3,975 Posts
        I have an article repository, I want to replace some words with chunks for little time or similar situation where I dont want to get down into previously written 100 articles to insert my code/chunk, but I know I have <!-- splitter --> tags in my articles, so I can change those <!-- splitter --> tags to insert adsense code inside articles without touching itself.

        Makes sense ? This little plugin is also an example to show how one can use MODx Plugins.

        ;)

        regards,

        zi
          Zaigham R - MODX Professional | Skype | Email | Twitter

          Digging the interwebs for #MODX gems and bringing it to you. modx.link
          • 6726
          • 7,075 Posts
          Yeah it makes sense, thanks for clearing that up smiley !
            .: COO - Commerce Guys - Community Driven Innovation :.


            MODx est l&#39;outil id
            • 26769
            • 5 Posts
            I think there is no need to use Chunks.

            $modx->documentOutput= str_replace('phrase_to_replace', 'new_phrase', $modx->documentOutput);
            $modx->documentOutput= str_replace('phrase_2_to_replace', 'new_phrase_2', $modx->documentOutput);