Search
Other ReReplacer questions
Forum

Using URL-params as rereplacer values?

cilap's Avatar cilap
hello together,

I am wondering if I can use URL parameters to replace text dynamically on the page.

E.g. let say I have following scenarios:

Scenario1:
example.com/myWildPath?urlParam1=myText1&myParam2=myText2
Now I would like to use the value of myParam1 and myParam2 as the replacement text in a article.

Scenario2:
example.com/myWildPath_myText1_myText2
Now I want to do the same as in scenario1, I want to replace the my text in a article with the encoded url params

Is there a way to achieve both scenarios?
If so, could you share a sample incl. the eventually needed php code?
Peter van Westen's Avatar Peter van Westen ADMIN
You can do something like:
<?php echo JFactory::getApplication()->input->get('urlParam1'); ?>
For the second one you would need to read in the url and extract the parts you need.

It is beyond my support to write your custom php.
Please post a rating at the Joomla! Extensions Directory
cilap's Avatar cilap
Hello Peter,

thank you for your quick reply

Okay got it how to fetch the params from JFactory for scenario1

But how can I now pass the parameters to ReReplcaer, or is there a better suggested way to replace text based on the URL-params?
Peter van Westen's Avatar Peter van Westen ADMIN
You can't pass parameters in the search. You can only use stuff captured via php in the replace.
Please post a rating at the Joomla! Extensions Directory
cilap's Avatar cilap
Peter van Westen wrote:
You can't pass parameters in the search. You can only use stuff captured via php in the replace.

sorry now completely confused.

Could you share me a example how to use the values of the params to do a search and replace? Or is it totally not possible?
Lets say I want to replace [someDummyText] in a article with the value of myParam1 of my example.
Peter van Westen's Avatar Peter van Westen ADMIN
You can search for predefined words and then replace them with stuff found in your url.
You cannot search for stuff that you pass in the url.
So only the replace has the ability to get data from the url (via php).
Please post a rating at the Joomla! Extensions Directory
cilap's Avatar cilap
got your point, but still unclear how to use it in combination with php and rereplace
do you have a simple example with a arbitrary text let say "someDummyText" and to repace it with the value of myParam1, let say myParam1=helloPeterHereTheValueOfTheParamPassedByTheUrl
Peter van Westen's Avatar Peter van Westen ADMIN
Like explained earlier, use this as the replacement:
You can do something like:
<?php echo JFactory::getApplication()->input->get('urlParam1'); ?>
Please post a rating at the Joomla! Extensions Directory
cilap's Avatar cilap
now got it. Was searching on how to add the php code in my article. But it was the replacement string in rereplacer. Works now and thank you.

I have a minor fix of your code to also take urlencoded URL-params
<?php echo JFactory::getApplication()->input->get('urlParam1', '', 'string'); ?>
Peter van Westen's Avatar Peter van Westen ADMIN
Yes, or:
<?php echo JFactory::getApplication()->input->getString('urlParam1'); ?>
Please post a rating at the Joomla! Extensions Directory
Ben Wachtel's Avatar Ben Wachtel
Thanks, I was able to use this technique to rewrite a 3rd party Joomla search landing page to include a link to search the entire site using Joomla core search:
You can also <a href = "/search/newest-first?searchphrase=all&searchword=<?php echo JFactory::getApplication()->input->getString('search'); ?>
">search our entire site</a>
Ed Rimkus's Avatar Ed Rimkus
I am attempting to do something similar with the following in Replace:
<?php 
echo str_replace("+", " ", JFactory::getApplication()->input->get(urldecode('utm_term')));
 ?>

If the search word triggered has multiple words they are inserted with a plus sign ('+') between the words in the search query. (...&utm_term=red+dog) The above does not replace the + with a space. Instead the words become concatenated on the page. reddog

I was tested the above with other characters like a dash or letter a, and those characters get replaced on the page.

Is there something different about a plus sign ('+')? How can I replace them with a space?

Ive got Case sensitive and RR_REPLACE_WITH_PHP toggled to 'Yes'.

TIA
Peter van Westen's Avatar Peter van Westen ADMIN
Not sure why you have the urldecode there. Doesn't make much sense.
You probably mea:
echo str_replace('+', ' ', urldecode(JFactory::getApplication()->input->get('utm_term')));

You mention 'RR_REPLACE_WITH_PHP'... Do you see that? Isn't the language string handled? Leads me to think that you do not have things installed correctly...
Please post a rating at the Joomla! Extensions Directory
Peter van Westen's Avatar Peter van Westen ADMIN
PS: as you can read here: docs4.regularlabs.com/rereplacer/going-f...hp-variables-objects

You can also use $app instead of JFactory::getApplication().
So:
echo str_replace('+', ' ', urldecode($app->input->get('utm_term')));
Please post a rating at the Joomla! Extensions Directory
Ed Rimkus's Avatar Ed Rimkus
Hi Peter,

Thank you for your quick response. Yes sir, I did have that urldecode in the wrong place. Thank you.

Even so, I have also tried it as you have it too:
echo str_replace('+', ' ', urldecode(JFactory::getApplication()->input->get('utm_term')));
and it is returning a concatenated search string.

I can use:
<?php 
if (isset($_GET['utm_term'])) {
    echo htmlspecialchars(urldecode($_GET['utm_term']), ENT_QUOTES, 'UTF-8');
}
?>
to get the desired results, but am concerned its not the Joomla! way.

I see RR_REPLACE_WITH_PHP as well as RR_MAX_REPLACEMENTS and RR_STRIP_SURROUNDING_P_TAGS in the ReReplacer Details Tab

RR_ENABLE_IN_EDIT_FORMS can be seen in the Search Areas Tab.

Do I need to uninstall and reinstall the Pro version?

Thanks again!
Ed Rimkus's Avatar Ed Rimkus
Thank you sir!

I used
echo str_replace('+', ' ', urldecode($app->input->get('utm_term')));
as suggested, and I still get a concatenated term

&utm_term=red+dog becomes reddog

Confidential information:
(hidden)
Peter van Westen's Avatar Peter van Westen ADMIN
The get() method on the Joomla input class will clean stuff from the strings. You probably want to use getString() instead.
Please post a rating at the Joomla! Extensions Directory
Ed Rimkus's Avatar Ed Rimkus
Thank you!!!
You can only post on the extension support forum if you have an active subscription and you log in

Buy a Pro subscription