ReReplacer

How to call ReReplacer using php?

7 months 6 days ago #88166

Dmitry Korotkov's Avatar Dmitry Korotkov

I use something like
$msg = JHtml::_('content.prepare', sprintf( $lang->_('SEND_NOTICE_VISIT_FIRST_MSG'), $to_user_name, $city_loc, $to_user, $to_user, $user->id, $user->name, $dashboard_link)
to prepare e-mail templates.
Could ReReplacer be initiated on the custom text?

7 months 6 days ago #88167

Peter van Westen's Avatar Peter van Westen Admin

First let me ask you: what level of php knowledge do you have.
Is this your own code (where you know what is going on and where the different parts come from), or is this some line of php you found somewhere?

7 months 6 days ago #88168

Dmitry Korotkov's Avatar Dmitry Korotkov

This is a part of my code. This code is used inside PHP form plugin.
I don't know how to mesure the php knowledge. I'd say experienced PHP programmer.

7 months 6 days ago #88169

Peter van Westen's Avatar Peter van Westen Admin

Ok, that makes explaining a bit easier 🙂

So you can pretty much run any php you want. But, you will need to set the variables you are using.
For instance: $to_user_name, is that a fixed string? Or based on some data you get from somewhere else.

If you want to echo out the result and those values of 'variables' will be defined in the ReReplacer item, then you could do something like:

echo JHtml::_('content.prepare', JText::sprintf('SEND_NOTICE_VISIT_FIRST_MSG', '...', '...', '...', '...', $user->id, $user->name, '...'));
You do not have to create the $user object. ReReplacer will create that for you when used.

Also read: www.regularlabs.com/extensions/rereplace...ial#replace-with-php

7 months 6 days ago #88170

Peter van Westen's Avatar Peter van Westen Admin

PS If you don't necessarily need to pass the string through the content plugins, you could just do:

echo JText::sprintf('SEND_NOTICE_VISIT_FIRST_MSG', '...', '...', '...', '...', $user->id, $user->name, '...');

7 months 6 days ago #88171

Dmitry Korotkov's Avatar Dmitry Korotkov

Thank you for the advice.
I put $lang to use language of mail recipient which could be other then current site language.
Anyway the issue is JHtml::_('content.prepare',$text) - didn't activate ReReplacer on the $text. What should I do to force content.prepare using also ReReplacer. I enabled the RR in everywhere area, make all publishing assignments but tags are not parsed. The tags keep unchanged in output. However in articles the tags work well.

7 months 5 days ago #88174

Peter van Westen's Avatar Peter van Westen Admin

This probably has to do with at what stage the replacements are done when the search area is set to 'Everywhere'. Not sure.
Try setting that to Content or Component.

6 months 3 weeks ago #88398

Dmitry Korotkov's Avatar Dmitry Korotkov

Can I request support when you make ReReplacer to parse content inside Fabrik form php plugin on my site? I need it to use articles as a templates for mails.

6 months 3 weeks ago #88405

Peter van Westen's Avatar Peter van Westen Admin

Sorry, I do not understand the question. ReReplacer can parse any php you give it in the replacement (when the PHP option is on).

6 months 3 weeks ago #88412

Dmitry Korotkov's Avatar Dmitry Korotkov

The ReReplacer works great in the Joomla output. But when I use in my php code JHtml::_('content.prepare', 'some ReReplacer tags') return tags but not the values.
The same content in article return appropriate output on the screen.

6 months 3 weeks ago #88414

Peter van Westen's Avatar Peter van Westen Admin

You have to specifically make sure you initialise the system plugins (not just the content plugins).
Also, passing content through the 'content.prepare' will only trigger the replacements set to 'Search Area': 'Content'.

6 months 2 weeks ago #88421

Dmitry Korotkov's Avatar Dmitry Korotkov

Thank you for the hint. I reorder system plugins in the Plugins manager and set the ReReplacer after system-Fabrik plugin (closer to the end of the system plugins list). I also changed the replacements area to 'Search Area': 'Content'. Now I understand that everywhere is not the content area.Peter van Westen wrote:

You have to specifically make sure you initialise the system plugins (not just the content plugins).
Also, passing content through the 'content.prepare' will only trigger the replacements set to 'Search Area': 'Content'.