1

I'm trying to create a class in EE, but for some reason it just won't work for me. I've even went as far as making it as easy as possible, but I always get:

The following tag has a syntax error:

{exp:my_class_name:testfunction}

Please correct the syntax in your template.

Here's the simple class:

class My_class_name {

    public $return_data;

    public function __construct(){
        $this->EE =& get_instance();
    }

    public static function usage(){
        ob_start();
        ?>
        Coming Soon, this is just filler for now.
        <?php
        $buffer = ob_get_contents();
        ob_end_clean();
        return $buffer;
    }

    public function testfunction(){
        $this->return_data = ee()->TMPL->tagdata;
    }

}

and usage:

    {exp:my_class_name:testfunction}
    hey
    {/exp:my_class_name:testfunction}
2
  • can u see your plugin in CP plugin list ?
    – Max Lazar
    Sep 30, 2014 at 5:18
  • BTW: "$this->EE =& get_instance();" is redundant now as you're using the super global ee() Sep 30, 2014 at 7:47

1 Answer 1

3

Your plugin class method needs to return the (parsed) tagdata instead of setting the $this->return_data property. The latter is only needed if the class constructor is used for template output. So:

public function testfunction()
{
    return ee()->TMPL->tagdata;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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