bernhard Posted July 29, 2017 Share Posted July 29, 2017 I built this module because I needed a versatile solution to replace tags and simple if-blocks in some E-Mails and PDF documents. If you only need to replace static tags (no if-conditions), then you can use default PW api and need no module: $str = "My favourite color is {color}."; $texttools = $sanitizer->getTextTools(); echo $texttools->populatePlaceholders($str, ['color' => 'red']); // output: My favourite color is red. Usage: See the two example Files in the folder /replacements Methods: replacementsTable() Renders an overview of all available replacements (see the example in the Module's config file: Create new Replacements: Simply copy the sample file and adopt to your needs. Download: https://gitlab.com/baumrock/RockReplacer 8 Link to comment Share on other sites More sharing options...
bernhard Posted July 29, 2017 Author Share Posted July 29, 2017 one more complex example: in the pdf creating module: $mpdf->WriteHTML(modules('RockReplacer')->replace($block->body, ['report' => $this->report])); the users edit-screen: the users help-section: the resulting pdf: and the replacementfile: <?php namespace RockReplacer; class dataoverview extends Replacer { public function desc() { return $this->_('Fügt eine Tabelle mit einer Zusammenfassung über alle Feedbacks + Rollen ein'); } public function replace($vars) { $report = $vars['report']; $project = $report->closest('template=project'); $fn = $report->fn; ob_start(); ?> <div class="dataoverview"> <h3><?= $this->_('Feedbackübersicht'); ?></h3> <table class="size-psmall striped"> <tr> <th class="text-center"><?= $this->_('Rolle'); ?></th> <th class="text-center"><?= $this->_('Eingeladen'); ?></th> <th class="text-center"><?= $this->_('Abgegeben'); ?></th> <th class="text-center"><?= $this->_('Rücklaufquote'); ?></th> </tr> <?php foreach($report->getRoles() as $role): ?> <tr> <td><?= $role->title ?></td> <td class="text-center"> <?php $invited = $this->wire->pages->count( "template=feedback". ",has_parent=$project". ",fn=$fn". ",fbrole=$role" ); echo $invited; ?> </td> <td class="text-center"> <?php $done = $this->wire->pages->count( "template=feedback". ",has_parent=$project". ",fn=$fn". ",fbrole=$role". ",fbdone=1" ); echo $done; ?> </td> <td class="text-center"><?= $invited ? round(($done/$invited)*100, 0) : 0 ?>%</td> </tr> <?php endforeach; ?> </table> [...] </div> <?php return ob_get_clean(); } } 4 Link to comment Share on other sites More sharing options...
dragan Posted July 29, 2017 Share Posted July 29, 2017 Looks nice! How is this different to Hanna Code? In the old days, when I used MODX, I used a lot of such tags (and MODX Evo snippets were all basically using similar syntax). Can RockReplacer generally speaking do more, i.e. is it more versatile? http://modules.processwire.com/modules/process-hanna-code/ 1 Link to comment Share on other sites More sharing options...
bernhard Posted July 30, 2017 Author Share Posted July 30, 2017 17 hours ago, dragan said: Looks nice! How is this different to Hanna Code? In the old days, when I used MODX, I used a lot of such tags (and MODX Evo snippets were all basically using similar syntax). Can RockReplacer generally speaking do more, i.e. is it more versatile? http://modules.processwire.com/modules/process-hanna-code/ i'm not sure but i think hannacode does not support the if statements like [myifstatement]this is shown only to superusers for example[/myifstatement] second, hannacode is a textformatter module that works only as a formatter for fields. i use my module to replace tags in emails and pdfs (ok that would also be possible with the textformatter and i'm thinking of adding a textformatter to call all my replacements, but i just wanted to have my own way of doing it...). and third, i prefer to define things with single files and not to write code into some field's config field. you can then use git for version control. next on the roadmap is to support else-statements like this: [superuser] access [else] sorry, only for superusers :) [/superuser] 5 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now