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

$message.messageHtml origin in message template

Discussion in 'XenForo Development Discussions' started by corbitWire1, Oct 27, 2011.

  1. corbitWire1

    corbitWire1 Member

    Ok...this is my first post. I've been watching the forum for a few months and I have to say that xenForo rocks! Because xenForo rocks, I decided to start writing my own mods :) Here is my first question/problem:

    I want to apply custom formatting to the first post of each thread. So I've overriden actionIndex() of XenForo_ControllerPublic_Thread through the use of my own class and a LoadClassController listener.

    My class is the following:

    PHP:
    <?php

    class SpecialPost_ControllerPublic_Thread extends XFCP_SpecialPost_ControllerPublic_Thread
    {
        public function 
    actionIndex()
        {
            
    $return parent::actionIndex();

            
    $postid $return->params['thread']['first_post_id'];
            if (isset (
    $return->params['posts'][$postid]))
            {
                
    $return->params['specialPost'][$postid] = $return->params['posts'][$postid];
                unset (
    $return->params['posts'][$postid]);
            }
            else
                
    $return->params['specialPost'] = array();

            return 
    $return;
        }

    }
    Also I've modified a chuck of the 'thread_view' template as follows:

    Code:
    <ol class="messageList" id="messageList">
    
    <xen:foreach loop="$specialPost" value="$post">
                <xen:if is="{$post.message_state} == 'deleted'">
                    <xen:include template="post_deleted_placeholder" />
                <xen:else />
                    <xen:include template="post" />
                </xen:if>
            </xen:foreach>
    
            <xen:foreach loop="$posts" value="$post">
                <xen:if is="{$post.message_state} == 'deleted'">
                    <xen:include template="post_deleted_placeholder" />
                <xen:else />
                    <xen:include template="post" />
                </xen:if>
            </xen:foreach>
            <xen:edithint template="attached_files" />
        </ol>
    The problem is that the first post doesn't display it's message and the post's owner signature. It seems that $message.messageHtml and $message.signatureHtml found in the 'message' template don't exist or they are empty. The problem exists only in my own code referencing $specialPost.

    I've checked the response of my controller and the base controller through print_r and neither $posts nor $specialPost contain a messageHtml or signatureHtml value. Where is the problem???
     
  2. Kier

    Kier XenForo Developer Staff Member

    Both are created in the View.

    See XenForo_ViewPublic_Thread_View, which calls XenForo_ViewPublic_Helper_Message::bbCodeWrapMessages()
     
    corbitWire1 likes this.
  3. corbitWire1

    corbitWire1 Member

    Kier, you are my hero! I searched almost everything regarding Thread stuff apart from XenForo_ViewPublic_Thread_View :rolleyes:

    I am in love with xenForo as it brings a revolution to user and developer experience. Thanks for this amazing product and keep up the good work!
     
    Kier likes this.
  4. James

    James Well-Known Member

    Did you consider simply applying template edits to the post using <xen:if is="{$post.position} == 0" />?
     
    corbitWire1 likes this.
  5. corbitWire1

    corbitWire1 Member

    Actually my question is a test. I'am trying to write a simple article system which will apply custom formatting to the first post of each thread supporting pages through the use of [PAGE] bbcode. I thought about $post.position but I found it more appropriate to have a different array element in viewParams which will contain current article's page and the respective section of the actual first post. But...thanks for your suggestion! My mod will function in a similar way to GARS for vBulletin functions. I'll release my mod when it's basic functionality is built :)
     

Share This Page