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

get first post object within thread_view template

Discussion in 'XenForo Development Discussions' started by localhost8080, Dec 26, 2014.

  1. localhost8080

    localhost8080 Well-Known Member

    Hello,

    I need the object of the first posting of a thread.

    All I have get gone is to get the flat array but not the populated object of the first posting by using

    Code:
    $postModel = XenForo_Model::create('XenForo_Model_Post');
    $post = $postModel->getPostById($this->_params['thread']['first_post_id']);
    
    at XenForo_ViewPublic_Thread_View

    I would need the value of

    Code:
    {$post.canLike}
    as it is accessed at post template.

    Someone knows about this?

    Thank you.
     
    Last edited: Dec 26, 2014
  2. Snog

    Snog Well-Known Member

    If you need it in PHP, check the post model for XenForo, it has a built in function 'canLikePost'.

    If you just need it in the thread_view template, $firstPost.canLike is already available in the template.
     
    localhost8080 likes this.
  3. localhost8080

    localhost8080 Well-Known Member

    yeah. thank you very much.
     
  4. localhost8080

    localhost8080 Well-Known Member

    Hello again.

    Someone knows how to get firstpost object of each thread in thread_list_item template easily?

    Thank you.
     
  5. Snog

    Snog Well-Known Member

    Maybe {$thread.first_post_id}?

    Or do you need the whole post?
     
  6. localhost8080

    localhost8080 Well-Known Member

    yes, but what to call to get post object with that id?
     
  7. Snog

    Snog Well-Known Member

    I don't think you can get the whole post by template calls in that template.

    Take a look at library/XenForo/ControllerPublic/Threads.php actionPreview. It's a good example of how to look up the full post info.
     

Share This Page