1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to post user info + user custom fields on a page

Discussion in 'Styling and Customization Questions' started by tajhay, Jul 12, 2012.

  1. tajhay

    tajhay Well-Known Member

    Hi,
    I have a sports forum. I have created players as members, complete with their pic as avatar, height/weight as custom fields etc.

    Now i want to output that info on a page. So basically I will create a page for each player.

    I can create the html template for the page, and want to know how to query the user so i can get info from their member pages. Can anyone assist?
     
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    That requires PHP code. In the case of a page node you can use a callback function. I can help with the code, but this seems redundant with the existing profile pages which already show all of a user's information. Is there a reason you aren't using profile pages?
     
  3. tajhay

    tajhay Well-Known Member

    Hi Jake, Reason why im not using profile pages are that it lists player names after you click them. Ontop of that i will need to edit the template to hide other fields like posting on their profile etc. Dont want that.

    I am simply trying to capture player info and put them against these dummy members. Instead of using another database i want to be able to use xenforo features and i feel custom fields will allow me a lot of flexibility in what i can do. For example in one page i want to have a green field, and the players avatars with perhaps just their name listed underneath it. I can create such page in html. when clicking on the player names or avatar it should bring out this page that i am requesting here where it shows players avatar, custom fields etc, that i am able to position anywhere on that page, so for example it could look like a wikipedia page of a sports player.

    Your help would be greatly appreciated mate
     
  4. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    I have attached a callback function you can use for your page node. Upload the PageNode.php file to library/Callback (create that directory). You need to specify the userid in that file:

    Code:
    <?php
    
    class Callback_PageNode
    {
    	public static function getUser(XenForo_ControllerPublic_Abstract $controller, XenForo_ControllerResponse_Abstract &$response)
    	{
    		$userId = 1;
    
    		$userModel = XenForo_Model::create('XenForo_Model_User');
    		$user = $userModel->getFullUserById($userId);
    		$user = $userModel->prepareUser($user);
    
    		$response->params['user'] = $user;
    	}
    }
    
    Then specify that callback for your page node:

    Screen shot 2012-07-12 at 10.46.49 PM.png

    Now you can access the $user variable in the template for your page node. This gives you access to the avatar and customFields:

    Screen shot 2012-07-12 at 10.47.20 PM.png

    Code:
    {$user.customFields.business_directory}
    
    <xen:avatar user="$user" size="m" />
    
     

    Attached Files:

    Motobaka and tajhay like this.
  5. tajhay

    tajhay Well-Known Member

    Thanks, I will have a few different members (around 20) that I will be creating a page for, so i have to have ~20 instances of that file? Is there an easy way to make it more configurable..id using the xencode in the template html to determine which user to get the info from?
     
  6. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Use this to read in the user_id from the URL:

    Code:
    <?php
    
    class Callback_PageNode
    {
    	public static function getUser(XenForo_ControllerPublic_Abstract $controller, XenForo_ControllerResponse_Abstract &$response)
    	{
    		$userId = $controller->getInput()->filterSingle('u', XenForo_Input::UINT);
    
    		$userModel = XenForo_Model::create('XenForo_Model_User');
    		$user = $userModel->getFullUserById($userId);
    		$user = $userModel->prepareUser($user);
    
    		$response->params['user'] = $user;
    	}
    }
    
    Now you pass the user_id via the URL like this:

    http://www.yoursite.com/pages/mypage/?u=1
     
    tajhay likes this.
  7. tajhay

    tajhay Well-Known Member

    thanks mate, ill try that tonight and see how i go
     
  8. jayramfootball

    jayramfootball Active Member

    I think this may be part what I am after..

    I want to allow my members to vote on player ratings for matches.
    On the new page I want to list the matches and when clicked go to an data capture form where ratings can be entered for each player.

    These ratings would then be written - along with some user details - to a new table in my database.

    Combined results from all users would then be displayed on the site...

    Will this code above allow me to get started with this?
     
  9. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Barely. There is a lot of code that still needs to be written to achieve all of that functionality. But the callback I posted shows how you can execute your own custom code and pass variables for use in the html of the page.
     
  10. jayramfootball

    jayramfootball Active Member

    Thanks Jake - I suspected that what I was after would require a lot of code:(
     
  11. MotMann

    MotMann Active Member

    ok.. and what i must wrote, if i need the first Thread (the newest) from here as full text and the next 5 threads shorten in the node? An that must work automatic :)

    And is that a problem for SEO?
     
  12. Market1234

    Market1234 Member

    Where would this code go? within the pagenode.php? I have a custom field called 'referral" and i would like it captured in my db at the least.

     

Share This Page