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.

Run vanilla code only and ignore site theme on custom pages

hi, I would like to use some vanilla functionalities and would like to create a custom page, ignoring the whole tpl and theme that I currently have.

I have tried this (vjrlinder version), it works but the theme is still loading with it. Any suggestions? thanks.

Tagged:

Comments

  • R_JR_J Ex-Fanboy Munich Admin

    Looking at Custom Pages, I'd say it is not possible. But what you are trying to achieve is very, very easy:

    <?php
    
    $PluginInfo['myPage'] = array(
        'Name' => 'My own page!',
        'Description' => 'A start...',
        'Version' => '0.1'
    );
    
    class MyPagePlugin extends Gdn_Plugin {
        public function pluginController_myPage_create($sender, $args) {
            var_dump($args);
        }
    }
    

    Save that as /plugins/myPage/class.mypage.plugin.php, enable it and go to yourforum.com/plugin/mypage

    Also try yourforum.com/plugin/mypage/Hello

    And you should add some more info to the plugin info, but it is not needed...

  • Thanks @R_J ! One thing is I would like to add more and don't want a plugin for each page, sort of the custom page plugin I guess.

  • R_JR_J Ex-Fanboy Munich Admin

    Simply call it myPages ;)

    You can add as many

    public function pluginController_foo_create() {} 
    public function pluginController_bar_create() {} 
    

    as you like.

    You can also do it like that

        public function pluginController_myPages_create($sender) {
            $this->dispatch($sender);
        }
    
        // available as plugin/mypages
        public function controller_index($sender) {
            echo __LINE__.'<br>';
            var_dump($sender->RequestArgs);
        }
    
        // available as plugin/mypages/foo
        public function controller_foo($sender) {
            echo __LINE__.'<br>';
            var_dump($sender->RequestArgs);
        }
    
        // available as plugin/mypages/bar
        public function controller_bar($sender) {
            echo __LINE__.'<br>';
            var_dump($sender->RequestArgs);
        }
    
  • R_JR_J Ex-Fanboy Munich Admin

    And if you prefer to see your new pages as "yourforum.com/nicename" you can do it like that:

    public function setup() {
        // Set custom route to plugin page.
        $router = Gdn::router();
        $pluginPage = 'plugin/mypages$1';
        $newRoute = '^nicename/.*)?$';
        if (!$router->matchRoute($newRoute)) {
            $router->setRoute($newRoute, $pluginPage, 'Internal');
        }
    }
    
    // Clean that routing.
    public function onDisable() {
        Gdn::router()->deleteRoute('^nicename/.*)?$');
    }
    

    Since setup() is only run when you enable your plugin, you would have to disable your plugin first an re-enable it afterwards if it is already enabled to see the effect.

  • hgtonighthgtonight ∞ · New Moderator

    I want to point out that you could just request the VIEW instead of the whole page.

    Also, I would extend the root controller if you want to create root endpoints instead of adding a route.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • Thanks R_J I will these codes asap!

  • @hgtonight said:
    I want to point out that you could just request the VIEW instead of the whole page.

    Also, I would extend the root controller if you want to create root endpoints instead of adding a route.

    It would be great if you could post a code example.
    This is an important topic and I'm not sure what you mean by that exactly.
    I thought you were referring to discussion_render_before at first, but not sure.

  • rbrahmsonrbrahmson "You may say I'm a dreamer / But I'm not the only one" NY ✭✭✭

    I'm not absolutely sure that's what @hgtonight referred to, but this code renders a page that is stored in the plugin's view folder and if you look at the rendered file itself you will see that it is a regular html file (not even php). So in theory you could create many such pages and render them at will.

    As explained earlier, the page is invoked through a dispather as shown here. Using the routing merely makes the url friendly.

  • hgtonighthgtonight ∞ · New Moderator

    @Kiori said:

    @hgtonight said:
    I want to point out that you could just request the VIEW instead of the whole page.

    Controllers in Garden have 2 universal parameters that change how a page is rendered. DeliveryType determines what gets rendered and DeliveryMethod determines how it gets rendered. For more information on the specific options available, check out the source code: https://github.com/vanilla/vanilla/blob/1005ef6d2c42ac7c104bc07d44cd58b1a408b1e1/library/core/class.controller.php#L151-L168

    Also, I would extend the root controller if you want to create root endpoints instead of adding a route.

    @R_J posted the exact thing I was thinking: https://vanillaforums.org/discussion/comment/231753/#Comment_231753

    Note that you do not have to use the dispatch method. You can just create a method on the root controller (i.e. the name of the function is the important part, not what goes into it).

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • Pragmatism is all I have to offer. Avoiding the sidelines and providing centerline pro-tips.

Sign In or Register to comment.