XF 1.0 Editing Templates and Defining a Callback for Pages

When we debuted the Pages feature, it was intended to be a simple way to get some custom HTML onto a page surrounded by the standard XenForo user interface chrome. By the time we reached Beta 1, it had evolved into an altogether more powerful system.

Pages now support a PHP callback, so your pages can request data from the database and be used as a platform for building any kind of single-page application you might want to build. They also allow you to override the default and specify your own template to be rendered by the page, so the possibilities really are limitless.

This two-part video shows you the basics of building a simple application using the Pages system, and delves into the realms of the template editor to create and edit the custom HTML that will be used to display your page.

To view this content we will need your consent to set third party cookies.
For more detailed information, see our cookies page.

Having built a basic dynamic page, in this second part we add more functionality and data to the page including a sidebar and a list of the authors of the most recent posts. In doing so, we look into advanced template syntax use, and reveal one of XenForo's hidden treasures.

To view this content we will need your consent to set third party cookies.
For more detailed information, see our cookies page.

Part 3
I've just uploaded a third part, answering some questions that have come up:

To view this content we will need your consent to set third party cookies.
For more detailed information, see our cookies page.

... and created a new answer post here:
http://xenforo.com/community/threads/random-questions-answered.114/page-2#post-102179
 
This is test site on localhost with screengrab of the error
The template is attempting to loop through $onlineUsers['records'] but your are setting your variable as $users.

Take this line:
PHP:
$response->params['users'] = $userModel->getLatestUsers(array(), array('limit'=> 5));
and replace it with this:
PHP:
$response->params['onlineUsers'] = $userModel->getLatestUsers(array(), array('limit'=> 5));
 
I don't believe that's actually possible, as both htaccess and WebDAV use HTTP Basic Auth.
I know this is an old thread, but I ran into this issue as well. For anyone who also runs into it, you can add this into your .htaccess file and it basically removes the webdav file from the HTTP Auth protection, allowing you to get access via WebDav.

Code:
<Files admindav.php>
order allow,deny
allow from all
satisfy any
</Files>

You can of course change it to below which should limit access to a specific IP address. (I haven't tested it though.)

Code:
<Files admindav.php>
order deny, allow
deny from all
allow from 123.123.123.123
satisfy any
</Files>
 
Hello, I am making a page following this tutorial, but when I use "respond" I have the following error : please use a valide callback method.

screenshot2012022413515.png


Thanks.
 
It means the callback method (either controller, or action) isn't valid - either the class can't be loaded, or the action is invalid (usually doesn't exist, or has a typo).
 
I just enabled this feature using the demo here...
I got it all to work...

The question is, what is the proper way to return the HTML inside the Template HTML area?
Or do I have to insert it into the template?

****EDIT: Just used the PAGE_CONTAINER html.
 
OK, I followed the video from Kier...
So this is what I did - maybe it'll help...

Under folder library - create a folder "Prod"
In this... Create two folders - "Model" and "PageCallBack"
In Model - create a file "Post.php"
In this file place
Code:
<?php
class Prod_Model_Post extends XenForo_Model_Post
{
    public function getMostRecentPosts($maxResults, array $viewingUser = array())
    {
        $postIds = $this->_getDb()->fetchCol(
            $this->limitQueryResults('
                SELECT post_id
                FROM xf_post
                ORDER BY post_date DESC
            ', $maxResults * 2
            )
        );
        $postResults = $this->getPostsByIds($postIds, array(
            'join' => XenForo_Model_Post::FETCH_THREAD
                | XenForo_Model_Post::FETCH_FORUM
                | XenForo_Model_Post::FETCH_USER
                | XenForo_Model_Post::FETCH_USER_PROFILE,
            'permissionCombinationId' => $viewingUser['permission_combination_id']
        ));
        $posts = array();
        foreach ($postResults AS $postId => $post)
        {
            $posts[$post['post_date'] . '_' . $post['post_id']] = $post;
        }
        krsort($posts);
        return array_slice($posts, 0, $maxResults, true);
    }
}




In the "PageCallBack" make a file called "AHPages.php"
In this file place the following code:

Code:
<?php
class Prod_PageCallback_AHPages
{
    public static function respond(XenForo_ControllerPublic_Abstract $controller, XenForo_ControllerResponse_Abstract $response)
    {
        $visitor = XenForo_Visitor::getInstance()->toArray();
        $sessionModel = $controller->getModelFromCache('XenForo_Model_Session');
        $response->params['onlineUsers'] = $sessionModel->getSessionActivityQuickList(
            $visitor,
            array('cutOff' => array('>', $sessionModel->getOnlineStatusTimeout())),
            ($visitor['user_id'] ? $visitor : null)
        );
        // fetch recent registrations
        $userModel = $controller->getModelFromCache('XenForo_Model_User');
        $response->params['users'] = $userModel->getLatestUsers(array(), array('limit' => 5));
        // fetch most recent posts
        $response->params['posts'] = self::_getPostModel($controller)->getMostRecentPosts(5, $visitor);
        $response->templateName = 'template_ahpages';
    }
    /**
     * @return Dev_Model_Post
     */
    protected static function _getPostModel(XenForo_ControllerPublic_Abstract $controller)
    {
        return $controller->getModelFromCache('Prod_Model_Post');
    }
}


Now when creating a new "Page"
In the PHP callback insert:

Prod_PageCallback_AHPages and respond
 
I know this is an old thread, but I can't find anything else (unless someone has a link?).

I've got my class setup in /library/PGMemberList/PageCallback/Members.php and I'm just using the example code from the video at the moment, modified with my class name:

Code:
<?php
 
class PGMemberList_PageCallback_Members {
 
  public static function respond(XenForo_ControllerPublic_Abstract $controller, XenForo_ControllerResponse_Abstract $response)
 
    $userModel = $controller->getModelFromCache('XenForo_Model_User');
    $response->params['users'] = $userModel->getLatestUsers(array(), array('limit' => 5));
 
    $response->templateName = 'pgmember_list';
  }
 
}

My template file just has a foreach loop of the user title as in the video.

But I can't save the page in the ACP when I enter the class name and method? Looking at the XHR request the page makes, the server responds with Internal Server Error 500.
I've also edited the database page entry with my class name and method, but then the resulting page node just shows up blank. Even with debug mode on for my IP Address I don't get any information about the error.

Any ideas?
 
I know this is an old thread, but I can't find anything else (unless someone has a link?).

I've got my class setup in /library/PGMemberList/PageCallback/Members.php and I'm just using the example code from the video at the moment, modified with my class name:

Code:
<?php
 
class PGMemberList_PageCallback_Members {
 
  public static function respond(XenForo_ControllerPublic_Abstract $controller, XenForo_ControllerResponse_Abstract $response)
 
    $userModel = $controller->getModelFromCache('XenForo_Model_User');
    $response->params['users'] = $userModel->getLatestUsers(array(), array('limit' => 5));
 
    $response->templateName = 'pgmember_list';
  }
 
}

My template file just has a foreach loop of the user title as in the video.

But I can't save the page in the ACP when I enter the class name and method? Looking at the XHR request the page makes, the server responds with Internal Server Error 500.
I've also edited the database page entry with my class name and method, but then the resulting page node just shows up blank. Even with debug mode on for my IP Address I don't get any information about the error.

Any ideas?
Post your issue in Development Discussions, just so we know you are licensed. I think non-licensed people go post here. But its also easier to track your issue there.
 
Hi,

I created a page node using this tutorial and I was successful but in side bar "members Online Now are shown as 0"

Pasting screenshot of another user where he was also getting Members Online Now as 0.

template_demo_error_msg-png.9553
Please tell me how to show correct members count? And I also want to show other side bars like new threads/new replies ... how to show them?
 
Please tell me how to show correct members count? And I also want to show other side bars like new threads/new replies ... how to show them?
Just to quickly answer your first question:

The template is attempting to loop through $onlineUsers['records'] but your are setting your variable as $users.

Take this line:
PHP:
$response->params['users'] = $userModel->getLatestUsers(array(), array('limit'=> 5));
and replace it with this:
PHP:
$response->params['onlineUsers'] = $userModel->getLatestUsers(array(), array('limit'=> 5));
 
Back
Top Bottom