ReReplacer

Advanced search and replace for Joomla!

  • Last updated: 26-Apr-2018
  • Version: 8.4.4
  • Types: Component System plugin
  • Joomla rating: 100%
Joomla rating: 100%

Do you like ReReplacer?

Rate it!

Examples for ReReplacer

As you will see with all these replacements, you are the one that decides what to search for and what to replace it with.

These are just some examples to get an idea of what you can do. You are of course free to modify these to fit your needs.

Simple text/html replacements

These are some examples of straight-forward text replacements.

Shortcut for Company details

With this example you can place 'COMPANY DETAILS' anywhere in your content and it will get replaced by nicely styled details, including links and images. Saves a lot of time!

Usage:

COMPANY DETAILS

Result:

Regular Labs
www.RegularLabs.com
Follow me on Twitter
Like me on Facebook

Search:

Enable the Case sensitive option.

COMPANY DETAILS

Replace:

<strong>Regular Labs</strong><br>
<a href="https://www.regularlabs.com">www.RegularLabs.com</a><br>
<a href="https://twitter.com/RegularLabs" target="_blank"><img src="https://regl.io/logo_twitter.png">Follow me on Twitter</a><br>
<a href="https://www.facebook.com/regularlabs" target="_blank"><img src="https://regl.io/logo_facebook.png">Like me on Facebook</a>

Add styling to words

This example adds a span with a classname to all occurrences of 'My Company Name'.
Once you have a classname, you can style it any way you want through css. Like changing the text color and size. Adding borders and backgrounds. Or even adding icons before or after it.

Search:

My Company Name

Replace:

<span class="my-special-class">My Company Name</span>

This replacement can however replace itself multiple times, as the result also contains what you are searching for.
I recommend you make sure the search text is not inside the final replaced output.
For instance, you can add extra spaces which your browser will ignore anyway, like:

<span class="my-special-class">My   Company   Name</span>

 

Or make this smarter via Regular Expressions.
In the following example, it will only replace 'My Company Name' if it is not followed by a < character.

Enable the Regular Expressions option.

Search:

My Company Name([^<])

Replace:

<span class="my-special-class">My Company Name</span>\1

Translating words to your desired language

In Joomla, pretty much all texts are taken from Language Files. This makes Joomla and extensions easily translatable.
However, not all extensions implement this correctly everywhere.

The best solution is of course to notify the extension developer and have it get fixed. But this does not always happen.
Instead of hacking the code of the extension, you can easily fix this through ReReplacer.

In this example we will be changing the word 'Cart' used in a shopping extension, for example, to 'Basket'.

Search:

class="shopping-cart">Cart</a>

Replace:

class="shopping-cart">Basket</a>

So the 'trick' here is to just add some unique html found surrounding the word in the html output of your page.

Note: With the Pro version of ReReplacer you can assign replacements to languages. This way you can make a different replacement per language.

Changing texts used in extensions to something else

The best solution is to see if these can be changed via the Language Overrides.

If not, see the above example.

Complex html replacements

These are some examples of more complex replacements done with the help of Regular Expressions.

Changing layout of extensions

Let's say you have an extension that outputs an image, then a paragraph of text and then a button. But you want this flipped around. So first the button, then the text, then the image.

In many cases - if the extension is coded well - this can be achieved via template overrides. However this is often quite some work and sometimes not possible.
With ReReplacer you can manipulate the output html in pretty much any way you want.

Ok, so let's take this as the html you find in the html output of your website.

<div class="panel">
	<img src="/path/to/some/image.png" alt="My Image">
	<p>Some text</p>
	<a href="/some/url.html" class="btn">Click here</a>
</div>

And you want this instead:

<div class="panel">
	<a href="/some/url.html" class="btn">Click here</a>
	<p>Some text</p>
	<img src="/path/to/some/image.png" alt="My Image">
</div>

No doing this via a simple text replacement will not work, because the text, image and url of the button are dynamic.

So we can use Regular Expressions.

Search:

(<div class="panel">)\s*(<img [^>]*>)\s*(<p>.*?</p>)\s*(<a [^>]* class="btn">.*?</a>)\s*(</div>)

Replace:

In the search, we are placing the different parts in groups, by surrounding stuff in parentheses (...).
We can then reference the captured text in these groups via \1, \2, \3, etc.
So all we need to do in the replacement is rearrange the order:

\1 \4 \3 \2 \5

Dynamic plugin-style tags

ReReplacer makes it possible and easy to make your own little custom plugin-style tags.
This means you can place a simple little text like {mytag} in your content that (usually dynamically) gets replaced with something more complex.

The below examples will use this curly bracket syntax. But you can implement it in whatever syntax you want.
So instead of {mytag} you might want to use something like [[mytag]] or __MYTAG__ or something completely different.
Because YOU write what to search for, YOU decide what the syntax of the tag should be.

Icon tag

This tag makes it easy to place font based icons.

Icon packages like Icomoon or Font Awesome give you a great way of placing icons on your site.
However, if you want to place these in your content, you generally have to switch to the html view and mess around in there.
Also, your editor might not even show the icon and maybe even strip it away when saving the article or item.
This tag solves that.

PS: Here is an overview of all the Icomoon icons available in Joomla!

Usage:

{icon joomla} {icon eye} {icon image} {icon star}

Result:

Search:

Enable the Regular Expressions option.

{icon (.*?)}

Replace:

<span class="icon-\1"></span>

Joomla Language string tag

This tag enables you to place language strings in your content. These will be passed through the Joomla language strings.

This requires the use of PHP code in the replacement, which is only available in the Pro version of ReReplacer.

Note: This will only work for language strings in language files that are loaded on the page. If you have your own custom language file you want to load, you need to force-load it in the php replacement.

Usage:

{translate JGLOBAL_SECRETKEY_HELP}

Result:

If you have enabled two factor authentication in your user account please enter your secret key. If you do not know what this means, you can leave this field blank.

Search:

Enable the Regular Expressions option.

{translate (.*?)}

Replace:

Enable the Treat as PHP option

<?php echo JText::_('\1'); ?>

Youtube video tag

Usage:

{youtube IEe7wbxez34}

Result:

Search:

Enable the Regular Expressions option.

{youtube (.*?)}

This search is very simple, but also very 'stupid'. It will not remove any surrounding <p> tags. And it doesn't check for the correct syntax in the youtube id.
This is a more complex but better Regular Expressions search:

(?:<p>)?\{youtube(?:\s|&nbsp;|&#160;)+([a-z0-9-_]+)\}(?:</p>)?

Replace:

<iframe width="200" height="113" src="https://www.youtube.com/embed/\1" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>

Vimeo video tag

Following the example for the Youtube tag above, you can do the same for a Vimeo tag.

Usage:

{vimeo 227088346}

Result:

Search:

Enable the Regular Expressions option.

{vimeo (.*?)}

Or better:

(?:<p>)?\{vimeo(?:\s|&nbsp;|&#160;)+([a-z0-9]+)\}(?:</p>)?

Replace:

<iframe width="200" height="113" src="https://player.vimeo.com/video/\1" frameborder="0" allowfullscreen></iframe>

Youtube modal popup tag

Instead of placing the video directly into your content (like done in the examples above), you might want to have it pop up in a modal. You can use ReReplacer to output Modals tags.
Note: The plugin ordering is important. When using ReReplacer to output code that needs to be handled by other Joomla plugins, make sure you order the ReReplacer system plugin before the others.

Usage:

{youtube IEe7wbxez34}

Result:

Search:

Enable the Regular Expressions option.

{youtube (.*?)}

Or better:

(?:<p>)?\{youtube(?:\s|&nbsp;|&#160;)+([a-z0-9-_]+)\}(?:</p>)?

Replace:

{modal url="https://www.youtube.com/embed/\1?autoplay=1&amp;rel=0"}
<img src="//img.youtube.com/vi/\1/mqdefault.jpg" alt="" />
{/modal}

Vimeo modal popup tag

Following the example for the Youtube tag above, you can do the same for a Vimeo tag.

Usage:

{vimeo 227088346}

Result:

Search:

Enable the Regular Expressions option.

{vimeo (.*?)}

Or better:

(?:<p>)?\{vimeo(?:\s|&nbsp;|&#160;)+([a-z0-9]+)\}(?:</p>)?

Replace:

Note: There is no way to directly link to the Vimeo thumbnail image. So you can either create your own, or use this custom php script.

{modal url="https://player.vimeo.com/video/\1?autoplay=1"}
<img src="/path/to/my/vimeo_image.php?id=\1" alt="" />
{/modal}