0
votes

In one custom module I write something like below. This module placed in the top of the page.

(650) 123-1232
950 Queen Dr Suite 110, Daly City CA, 94015

In another custom module I write the same thing with few changes as below. This module placed in the bottom of the page.

950 Queen Dr Suite 110, Daly City CA, 94015
(650) 123-1232

The problem is I repeat the same content over and over again in custom modules and mistakes are probable to happen. So what I want to do is to use short tags as below.

{phone}
{address}

If I write a short tag as above in a custom modules I want them to replaced with some specific values all over the site. {phone} with (650) 123-1232 and {address} with 950 Queen Dr Suite 110, Daly City CA, 94015. Assume that values are already in the database.

Can this be achieved by write a Joomla plugin? Or what should I do? How can this be done?

2

2 Answers

1
votes

If plugins are executed for the module, you can use this for example

class plgContentShorttags extends JPlugin
{

    public function onContentPrepare($context, &$row, &$params, $page = 0)
    {
        // Don't run this plugin when the content is being indexed
        if ($context == 'com_finder.indexer') {
            return true;
        }

        if (JString::strpos($text, '{phone}') !== false) {
            $row->text = JString::str_ireplace('{phone}', '(650) 123-1232', $row->text);
        }

        if (JString::strpos($text, '{address}') !== false) {
            $row->text = JString::str_ireplace('{phone}', 'your address', $row->text);
        }

        return true;
    }
}

You just need to add plugin xml and install it. You can even add parameters to the plugin to set details via backend

1
votes

ReReplacer - search and replace in your websites output. This gets the job done.

ReReplacer is a Joomla! component and system plugin that enables you to replace anything in your Joomla! site’s output with whatever you want.

ReReplacer will search the text (html) of your pages for your search request and replace it with what you have told it to do. These replacements are on the fly. That means they are not permanent. They are done every time you request a web page in your site.

This gives you great possibilities and power to manipulate the output of your site.