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

Format post data AND get thread link

Discussion in 'XenForo Development Discussions' started by TerminalAddict, Mar 2, 2011.

  1. TerminalAddict

    TerminalAddict Active Member

    A little background.
    I have a small class that I want to use to create my home page (the way I like it :) )
    class FPS_HomePage_PageCallback_HomePage
            public static function 
    response(XenForo_ControllerPublic_Abstract $controllerXenForo_ControllerResponse_Abstract $response)
    // do some raw stuff perhaps?
    $fps_intro = Array();
    $fps_current_giveaway = Array();
    $fps_previous_giveaway = Array();

    // get models
    $postModel $controller->getModelFromCache('XenForo_Model_Post');
    $threadModel $controller->getModelFromCache('XenForo_Model_Thread');

    // get a single post for our ABOUT section
    $fps_intro $postModel->getPostById(63); //post id for the post I want to use.

    // get the previous giveaways thread
    $fetchOptions = array(
    'limit' => 5,
    'order' => 'node_id',
    'orderDirection' => 'desc',
    $conditions = array(
    'deleted' => false,
    'moderated' => false
    $threads $threadModel->getThreadsInForum(111$conditions$fetchOptions); // forum id where I post giveaways.

    $count 1;
    foreach (
    $threads as $key => $value ) {
    $fps_previous_giveaway[$count] = Array('thread_id'=>$value['thread_id'], 'title'=>$value['title'], 'post_date'=>date('F j, Y',$value['post_date']), 'post_id'=>$value['first_post_id']);

    // The latest giveaway is simply the first in the array of previous giveaways :)

    $fps_current_giveaway['post_id'] = $fps_previous_giveaway[1]['post_id'];
    $fps_current_giveaway['thread_id'] = $fps_previous_giveaway[1]['thread_id'];
    $fps_current_giveaway['title'] = $fps_previous_giveaway[1]['title'];
    $fps_current_giveaway['post_date'] = $fps_previous_giveaway[1]['post_date'];
    $fps_current_giveaway['contentId'] = $postModel->getPostById($fps_previous_giveaway[1]['post_id']);
    $fps_current_giveaway['content'] = $fps_current_giveaway['contentId']['message'];

    $response->templateName 'FPS_HomePage';
    $response->params += array(
    'FPS_intro' => $fps_intro['message'],
    'FPS_current_giveaway' => $fps_current_giveaway,
    'FPS_previous_giveaway' => $fps_previous_giveaway
    // var_dump($fps_previous_giveaway[1]);
    this will return 1 var, and two arrays.

    the "contents" of each return value looks like this
    Your friend TerminalAddict has a link
    Thanks, and enjoy
    how do I turn this into HTML ?

    what I have so far: http://www.fps.net.nz/community/pages/Home/

    btw, I've watched this http://vimeo.com/16239304 twice! :) (mainly so I can see some of the code in the vid)
    plus, a great deal of thanks to Arik here: http://xenforo.com/community/threads/template-pagecallback-and-wordpress.12885/

    so, is there a Model that I can use to format the "contents" ?

  2. TerminalAddict

    TerminalAddict Active Member

    whoops .. forgot to change the title of this thread :)
    While I was typing this out, I figured out how to do thread links using <xen:link> :)
  3. TerminalAddict

    TerminalAddict Active Member

    bump .. can anyone help?
  4. Shadab

    Shadab Well-Known Member

  5. TerminalAddict

    TerminalAddict Active Member

  6. Shadab

    Shadab Well-Known Member

    In your page html, instead of using {$yourMessageVariableName} to output the parsed message, use
    {xen:raw $yourMessageVariableName}
    TerminalAddict likes this.
  7. TerminalAddict

    TerminalAddict Active Member

    awesome ! thanks!

Share This Page