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

I get an error with this listener

Discussion in 'XenForo Development Discussions' started by Matthew Hawley, Mar 12, 2013.

  1. Matthew Hawley

    Matthew Hawley Well-Known Member

    Im trying to create an addon and I'm getting an error with this listener. What's wrong with it?
    This is from http://xenforo.com/community/resour...-insert-tabs-in-profile-page-using-hooks.335/
    Code:
    <?php
    //Look! The name of the class follow our directory structure!
    //nameOfTheAddon_File (without the ".php" for sure!)
    //This can be: nameOfTheAddon_Folder_File or nameOfTheAddon_Folder_Folder_File
    class findPostsInThread_Listener
    {
        //Our callback signature! We are using here! Look:
        public static function template_hook ($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template)
        {
            //Yey! its our template hook!
            if ($hookName == 'thread_view_pagenav_before')
            {
                //Our tab! We will do somethin better, hang on.
                $contents .= '<label><a href="{xen:link search/search, '', 'type=post', 'thread_id={$thread.thread_id}', 'users={$visitor.username}'}">Your Posts</a></label>';
            }
        }
    }
    ?>
     
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    What is the error?
     
  3. Jeremy

    Jeremy XenForo Moderator Staff Member

    PHP:
                $contents .= '<label><a href="{xen:link search/search, '', 'type=post', 'thread_id={$thread.thread_id}', 'users={$visitor.username}'}">Your Posts</a></label>';
    should be
    PHP:
                $contents .= '<label><a href="{xen:link search/search, \'\', \'type=post\', \'thread_id={$thread.thread_id}\', \'users={$visitor.username}\'}">Your Posts</a></label>';
    You need to escape the single quotes found within the quote, or you build an invalid string, causing the syntax error you are receiving.
     
    Matthew Hawley likes this.

Share This Page