Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Using views in plugins

edited August 2010 in Vanilla 2.0 - 2.8
Hello!

I am workin on getting familiar with how to make my own plugins with Vanilla and am wondering about something very basic. And that is how to use views with plugins.

In the default.master.php I added a line like this:
$this->FireEvent('MyTestEvent');

And in my plugin file, I added an event handler like this:
public function Base_MyTestEvent_Handler(&$Sender) {
echo 'My Test Event';
}

It works fine. But I don't want to have to add a whole lot of echo '' in my plugin files. I'd rather use views. After having studied some of the plugins that have been released, I am left a bit more confused as of how to use views. The documentation doesn't help me much either. Does anyone have any tips on how to set up views for plugins?
Tagged:

Comments

  • ToddTodd Chief Product Officer Vanilla Staff
    Try this:
    1. Create your view file in your views folder (ex. views/view.php).
    2. Echo the view from the event with the following code:
      echo $Sender->FetchView($this->GetView('view.php');
  • Wonderful! :) Thank you!

    Would you happen to know what's the difference between these two lines?
    $Sender->Render($this->GetView('viewfile.php'));
    echo $Sender->FetchView($this->GetView('viewfile.php'));
  • I believe the Render function will output the whole site, including the layout.
    The FetchView function will just return the view so you can echo it.
Sign In or Register to comment.