3

I'm new to Joomla. The first time I create a plugin. I am trying to create a new plugin, but it does not work. Events did not react.

Joomla version 3.4.8. PHP 5.6

My Code

plgcontenttitlere.php

    defined( '_JEXEC' ) or die;
jimport('joomla.plugin.plugin');
echo 'test'; // WORKING!
class plgContentTitlere extends JPlugin
{
    protected $autoloadLanguage = true;

    function __construct( &$subject , $config ) {
    parent::__construct($subject, $config);
         echo 'TEST'; // DOESN"T WORK!
    } 
     public function onContentPrepare($context,&$row, &$params, $limitstart) {
          echo 'TEST'; // DOESN"T WORK!
    }
}

File plgcontenttitlere.xml

<?xml version="1.0" encoding="utf-8"?>
<extension version="3.1" type="plugin" group="content" method="upgrade">
    <name>Content - TitleRe</name>
    <creationDate>March 2016</creationDate>
    <copyright>Copyright (C) 2016 - Vektor Media. All rights reserved.</copyright>
    <license>GNU General Public License version 2 or later; see LICENSE.txt</license>
    <version>0.1.0</version>
    <files>
        <filename plugin="plgcontenttitlere">plgcontenttitlere.php</filename>
        <filename>index.html</filename>
    </files>
    <config>
    </config>
</extension>

As you can see the output before plugin echo 'test' the work. But inside it does not work. error_reporting does not display an error

4

The naming convention of the plugin files must be proper. This might be the issue why your plugin class is not rendering. See the example below:

Plugin File: nameofplugin.php

class plgContentNameofplugin extends JPlugin {
 //plugin code
}

XML File: nameofplugin.xml

<files>
   <filename plugin="nameofplugin">nameofplugin.php</filename>
</files>

Please refer the following link for more details:

https://docs.joomla.org/J3.x:Creating_a_content_plugin

See the modifications below you would need to do:

  • Rename the 2 files as : titlere.php and titlere.xml
  • In titlere.xml, modify the following:

    <files> <filename plugin="titlere">titlere.php</filename> <filename>index.html</filename> </files>

  • zip the files install it and check, or modify the installed files and check.

Reason: you are naming as plgcontenttitlere which is wrong because plg denotes plugin type, content denotes the content type and titlere is the name of your plugin and therefore, files must be named this way.

  • I tried, but doesn't work – Jawlon Rodriguez Apr 8 '16 at 7:54
  • @JawlonRodriguez I have modifed the answer for you now after seeing your manifest file, please try as above again – Liz. Apr 8 '16 at 12:58
  • YES, Thank you @Ruchika ever so much! respect :) – Jawlon Rodriguez Apr 8 '16 at 13:12
  • it is our pleasure to be helpful :) – Liz. Apr 8 '16 at 13:21
0

I'm not an expert, but I'll try to point out a couple of things.

1) Looking at your code, the problem (I'm pretty sure) is that echo doesn't go somewhere. If onContentBeforeDisplay is anything like onContentPrepare, then your code should be something like:

$row->text="test".$row->text;

I'm guessing this is really your problem.

2) Without seeing the manifest for the plugin, it's really impossible to say. I've done things like forget a file from the manifest, and then have the thing not work.

  • manifest added. $row->text="test".$row->text; doesn't work – Jawlon Rodriguez Apr 8 '16 at 8:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.