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.

Creating a Plugin and Can't Render View File Properly

I'm creating a simple plugin that is only going to display a few PHP pages with different paths, such as...


The problem is that only the first page renders properly and everything else in the folder displays the theme with an empty page. Here is part of my code from class.myplugin.plugin.php...

public function pluginController_MyPlugin_create($sender, $args) {

      // Setup head.
      $sender->MasterView = '';
      $sender->CssClass = 'NoPanel';

      if ($args[0] != '') {
          $page = $args[0];
      } else {
          $page = null;

      if($page == null){
        $sender->render('myplugin', '', 'plugins/MyPlugin');
        if(file_exists('plugins/MyPlugin/views/' . $page . '.php')){
          // echo $page; (this actually echoes the page name properly above the theme, but the won't render the page with the code below)
          $sender->render($page, '', 'plugins/MyPlugin');
          //would like to render a 404 page here if you know how

The route is setup properly like so...



My folder structure is...


page1.php has unique content but if I go to, I only get the empty page with the theme. If I go to, it will display the contents from myplugin.php just fine.

All the view files are similarly coded like this...

<?php defined('APPLICATION') or exit();
echo "unique content";


  • Options
    R_JR_J Ex-Fanboy Munich Admin

    You can do it like that:

        public function pluginController_dispatcher_create($sender, $args) {
            // "myplugin" in your case, but I found "index" better ;-)
            $page = val(0, $args, 'index');
            // Try to find a matching file in this plugin/views
            $view = $this->getView($page.'.php');
            // Check if this file exists and is readable
            if (!is_readable($view)) {
                // If not, throw default error message
                throw notFoundException();
            // Show the requested view
  • Options
    R_JR_J Ex-Fanboy Munich Admin
    edited January 2017

    If you need something more sophisticated, you can do it like it is shown in the official example plugin:

        public function pluginController_dispatcher_create($sender) {
            $this->dispatch($sender, $sender->RequestArgs);
        // or
        public function controller_index($sender, $args) {
        public function controller_page1($sender, $args) {
            // do logic specific for page1
  • Options

    Thanks :) That really cleaned things up for me.

    Turns out I didn't have the proper permissions on the page1.php and page2.php files. The is_readable function tipped me off and now everything works perfectly!

Sign In or Register to comment.