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

is Custom Pages plugin working on Vanilla 2.6?

This discussion is related to the Custom Pages addon.


I was using BasicPages plugin to add custom static pages to my vanilla forum website but it turns out I can't add modules to the content of basicpages.

I've downloaded Custom Pages to give that a try but I cannot get the link for it to show up in the admin dashboard so I'm not sure how to use it. I've deleted the cache folder and allowed it to rebuild but still not showing. Is this working in 2.6 or am I doing something wrong?

The goal is to add a landing page to my website that will be the new home/root page and will contain static content and then below the static content I want it to show the latest 5 discussions. What is the best way to achieve this?


  • mroth7684mroth7684 New
    edited January 2019

    I was just browsing the vanilla forum showcase and saw a couple websites that are basically doing what I want to do. https://community.acer.com/en/ and https://community.dentistry.com/

    Are they using an application or plugin to do that or is it just a custom page with the categories and discussions module embedded? or would it be done in the theme and view template?

  • Update: I got custom pages plugin to work. I found an old comment that has a fix for newer vanilla forums.

    However I would still like some help with how to get discussions to show on a custom page. I found a discussion that says to make a custom theme module and use the discussions module and view from vanilla core as the template. So if I do that and rename it to HomepageModule how would I then access the homepage module from the browser? I know how to add routes to shorten the URL to what I want but I am not sure of the path to use.

  • R_JR_J Ex-Fanboy Munich Admin

    In theory it should be like this:

    Your custom html content
    // Minimal environment needed to use most of Vanilla's framework.
    // Require the bootstrap to configure the application.
    $discussionsModule = new DiscussionsModule();
    echo $discussionsModule->toString();
    Continue your custom html

    Save that into the root folder of your forum and if it's not working give feedback

  • R_J thank you for your post. I'm at work now but I will try out the code later today.

    I'm assuming since you said to put the code in the root folder that I should name this file something like home.php? then I can set home.php as the path for forumroot in the routes settings.

  • R_JR_J Ex-Fanboy Munich Admin

    Exactly like that

  • @R_J said:
    Exactly like that

    For some reason I could not get the page to display with the file in the forum root. "page not found" error.

    However by adding the following code to my Custom Page plugin page the discussion module does show up.
    <?php $discussionsModule = new DiscussionsModule(); echo $discussionsModule->toString(); ?>

    However I see that the data displayed is minimal. I would like to get the rest of the data like author, avatar, and category. I see in the class.DiscussionsModule.php file that I'll need to add some of those functions to the custom page to do that. Or is there a better way to do it?

    My apologies if this should be known. I'm familiar with python programming but PHP is new to me. I'm trying my best.

  • R_JR_J Ex-Fanboy Munich Admin

    Not much time for explanations, sorry! The file attached is a short plugin which should basically work.

    Vanilla uses a front controller which means that every file access is routed through the index.php file. Therefore something like "home.php" couldn't be found. Maybe it is better to realize this as a plugin.

    You can reuse some parts of the plugin to show the html markup like it is used in the forum, but all the CSS is missing. You will have to work on it for sure. Maybe you should take a look at the writeDiscussion function and simply pick from it what you like.

  • Thank you again. I was able to install the plugin and render the custom page view with the theme and Recent Discussions information. Hopefully I can customize it from here now that I understand it a bit more.

  • Hi @R_J I'm wondering if you can help me with this one more time. I don't think the avatar and original author info for discussions is being returned. I enabled the built-in plugin to show original posters avatar on each discussion. But I am not seeing how I would make it work on the homepage discussions also. Here's my code so far the HomePage view is at the bottom, I can't figure out how to end the first code block:


    class HomePagePlugin extends Gdn_Plugin {
         * Create a new page and display the view
         * @param PluginController $sender Insatnce of the calling class
         * @return void
        public $Limit = 10;
        /** @var bool Whether to show the discussion author avatar. */
        private $showPhotos = true;
        /** @var array Limit the discussions to just this list of categories, checked for view permission. */
        protected $categoryIDs;  
         * @param $showPhotos Whether to show the discussion author avatar.
         * @return DiscussionsModule
        public function setShowPhotos($showPhotos) {
            $this->showPhotos = $showPhotos;
            return $this;
         * @return bool Whether to show the discussion author avatar.
        public function getShowPhotos() {
            return $this->showPhotos;
        public function pluginController_HomePage_create($Sender) {
            $Sender->MasterView = 'default';
            $Session = Gdn::session();
            if (!function_exists('writeDiscussion')) {
                include($Sender->fetchViewLocation('helper_functions', 'discussions', 'vanilla'));
            // Fetch discussions from model.
            $discussionModel = new DiscussionModel();
            $categoryIDs = $this->getCategoryIDs();
            $where = ['Announce' => 'all'];
            if ($categoryIDs) {
                $where['d.CategoryID'] = CategoryModel::filterCategoryPermissions($categoryIDs);
            } else {
                $visibleCategoriesResult = CategoryModel::instance()->getVisibleCategoryIDs(['filterHideDiscussions' => true]);
                if ($visibleCategoriesResult !== true) {
                    $where['d.CategoryID'] = $visibleCategoriesResult;
            $Sender->Data['HomePageDiscussions'] = $discussionModel->getWhereRecent($where, $limit);
         * Get a list of category IDs to limit.
         * @return array
        public function getCategoryIDs() {
            return $this->categoryIDs;
         * Set a list of category IDs to limit.
         * @param array $categoryIDs
        public function setCategoryIDs($categoryIDs) {
            $this->categoryIDs = $categoryIDs;
        All the code below is taken from class.controller.php
        It is needed to use Vanillas "writeDiscussion" function
        /** @var array The data that a controller method has built up from models and other calculations. */
        public $Data = [];
         * Set data from a method call.
         * If $key is an array, the behaviour will be the same as calling the method
         * multiple times for each (key, value) pair in the $key array.
         * Note that the parameter $value will not be used if $key is an array.
         * The $key can also use dot notation in order to set a value deeper inside the Data array.
         * Works the same way if $addProperty is true, but uses objects instead of arrays.
         * @see setvalr
         * @param string|array $key The key that identifies the data.
         * @param mixed $value The data.  Will not be used if $key is an array
         * @param mixed $addProperty Whether or not to also set the data as a property of this object.
         * @return mixed The $Value that was set.
        public function setData($key, $value = null, $addProperty = false) {
            // In the case of $key being an array of (key => value),
            // it calls itself with each (key => value)
            if (is_array($key)) {
                foreach ($key as $k => $v) {
                    $this->setData($k, $v, $addProperty);
            setvalr($key, $this->Data, $value);
            if ($addProperty === true) {
                setvalr($key, $this, $value);
            return $value;
         * Get a value out of the controller's data array.
         * @param string $path The path to the data.
         * @param mixed $default The default value if the data array doesn't contain the path.
         * @return mixed
         * @see getValueR()
        public function data($path, $default = '') {
            $result = valr($path, $this->Data, $default);
            return $result;

    homepage.php view:

    Recent Discussions

      <?php foreach ($this->Data['HomePageDiscussions'] as $Discussion) { writeDiscussion($Discussion, $this, $Session); } ?>
Sign In or Register to comment.