Author Topic: Newbie question, show template when taskbar button is pressed  (Read 8540 times)

Offline bluebook79

  • Newbie
  • *
  • Posts: 1
Newbie question, show template when taskbar button is pressed
« on: February 11, 2022, 08:25:16 AM »
Hi

I'm trying to create a roundcube plugin. I have managed to add a button to the taskbar and I've created a template file in skins/elastic/templates/mytemplate.html . Now I want the template to be displayed when the taskbar button is pressed.

This is what i've got so far

Code: [Select]
class my_plugin extends rcube_plugin
{
    //Plugin initialization
    function init()
    {
        $this->load_config();
        $this->add_texts("localization/");

        $this->add_hook("startup", array($this, "create_gui"));
    }

    function create_gui($args)
    {
        $this->include_stylesheet($this->local_skin_path()."/files.css");
        //Add taskbar button
        $this->add_button(array(
          "command"    => "files",
          "class"      => "eg-button-files",
          "classsel"   => "eg-button-files eg-button-files-selected",
          "innerclass" => "eg-inner inner",
          "label"      => "my_plugin.files",
          "type"       => "link"
        ), "taskbar");

    }
}

Offline JohnDoh

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2,845
Re: Newbie question, show template when taskbar button is pressed
« Reply #1 on: February 15, 2022, 03:17:31 AM »
Have a look at the help plugin which ships with Roundcube for an example. Its something like this:

Code: [Select]
class my_plugin extends rcube_plugin
{
    //Plugin initialization
    function init()
    {
        $this->load_config();
        $this->add_texts("localization/");

        $this->add_hook("startup", array($this, "create_gui"));
       
        // register a new task for this plugin
        $this->register_task('my_plugin');
       
        // register a handler for the default task action
        $this->register_action('index', [$this, 'mytemplate']);
    }

    function create_gui($args)
    {
        $this->include_stylesheet($this->local_skin_path()."/files.css");
        //Add taskbar button
        $this->add_button(array(
          "command"    => "switch-task",
          "prop"       => "my_plugin",
          "class"      => "eg-button-files",
          "classsel"   => "eg-button-files eg-button-files-selected",
          "innerclass" => "eg-inner inner",
          "label"      => "my_plugin.files",
          "type"       => "link"
        ), "taskbar");

    }

    function mytemplate()
    {
        $rcmail = rcmail::get_instance();
        // register handler for template object "my_plugin.body"
        $rcmail->output->add_handler('my_plugin.body', [$this, 'body']);
        // output template called mytemplate.html
        $rcmail->output->send('my_plugin.mytemplate');
    }

    function body($attrib)
    {
        return "<b>content</b>";
    }
}
Roundcube Plugins: Contextmenu, SpamAssassin Prefs, and moreā€¦