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
-~----------~----~----~----~------~----~------~--~---