Benedikt R. In the book Practical CakePHP Projects, the authors discuss CakeTags in chapter 11. They use a subclass of Views that handles substitution of content in the last stages of rendering. I've modified theirs to handle a <codesample > tag. In the view, I render any <codesample file='filename'/> tags as the content of the file embedded in a <div>
http://books.google.com/books?id=3S0O6Egf-_4C&pg=PA317&lpg=PA317&dq=cakephp+caketags&source=bl&ots=z45NEFP37N&sig=9sTxAN7W2v7Anaj3sF3X9ZFh4cc&hl=en&ei=QasYSqmRJ4zMMNqbzZYP&sa=X&oi=book_result&ct=result&resnum=3 http://v2.cybergod.net/codesamples.zip -teh On May 23, 1:44 am, "Benedikt R." <[email protected]> wrote: > Hey! > > Is there a cool way to parse content before doing an output? > > In the text items in my database I got placeholders like '[BLA...]' - > these should be replace by specific source code, that's read from some > files. > > The tool should also be available in the views, and be used like this: > $this->Articles[Article][content]->replacePlaceholders(); > > I just created a component, that helps me with that: > > <?php > class ElementReplacerComponent extends Object { > > public $replacementsFolder = 'contentReplacements/'; > > public $searchTemplate; > public $searchContent = ''; > > public $adSenseTemplate; > public $adSenseContent = ''; > > function initialize () { > $searchTemplate = $this->replacementsFolder . > 'searchField.tpl'; > $adSenseTemplate = $this->replacementsFolder . > 'googleAdSense.tpl'; > > if ( file_exists( $searchTemplate ) ) { > $fileHandler = fopen($searchTemplate, 'r'); > $this->searchContent = fread($fileHandler, > filesize > ($searchTemplate)); > fclose( $fileHandler ); > } > > if ( file_exists( $adSenseTemplate ) ) { > $fileHandler = fopen($adSenseTemplate, 'r'); > $this->adSenseContent = fread($fileHandler, > filesize > ($adSenseTemplate)); > fclose( $fileHandler ); > } > } > > function parseContentItem( &$content ) { > $content = str_replace('[BLZ-Suche]', > $this->searchContent, > $content); > $content = str_replace('[Google AdSense]', > $this->adSenseContent, > $content); > > return 0; > } > } > ?> > > Is there a better way to do that (I think there is :-D)? > > Best regards, > Benedikt --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---
