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

How can I add $viewParams for use in the logo_block template?

Discussion in 'XenForo Development Discussions' started by AndyB, Mar 31, 2014.

  1. AndyB

    AndyB Well-Known Member

    I'm creating a new add-on which I need to update a link in the header every five minutes. Because this link is always changing I would like to use the following code in a PHP file to make available in the logo_block template.

    PHP:
    $viewParams = array(
        
    'link' => $link
    );

    // add viewParams to parent params
    $parent->params += $viewParams;
    This is an example of the PHP code I would use when I extend a ControllerPublic PHP file. But I'm not sure which file I need to extend that would allow me to use this code that will be available in the logo_block template.

    This tutorial by Fuhrmann:

    http://xenforo.com/community/resources/how-to-create-your-own-helpers.332/

    shows how to create a new helper, but I was hoping to be able to use viewParams instead.

    Thank you.
     
  2. Fuhrmann

    Fuhrmann Well-Known Member

    Hey Andy! Well, I think the best way to do this is create a new Code Event Listener to the template_render and pass your parameters to the template being rendered. I don't have a Xenforo installation so I can send you screenshots and explain step by step, but when I get in home I can help you more.
     
  3. AndyB

    AndyB Well-Known Member

    Hi Fuhrmann,

    Thank you for your reply and offering to help.

    I figured out a way to accomplish what I needed to do by creating a Route and using a redirect.

    1) Cron creates a text file which contains the path to an attachment
    2) Image in header when clicked directs to route function
    3) Route function reads text file which contains the path to the attachment and redirects to appropriate post
     
    Fuhrmann likes this.
  4. AndyB

    AndyB Well-Known Member

    In post #3 I indicated that I found a solution, however the problem is after five minutes the Cron runs and the kink is no longer valid.

    What I would like to do is explore the suggestion @Fuhrmann indicated in post #2. If anyone knows how I can pass a variable into the logo_block template that is what I need to do.

    Thank you.
     
    Fuhrmann likes this.
  5. Syndol

    Syndol Guest

    Hi Andy, where in the template is this link located? Could you not use the header_logo hook to add it?
     
  6. AndyB

    AndyB Well-Known Member

    Hi Syndol,

    This is for my Header Thumbs add-on located here:

    https://xenforo.com/community/resources/header-thumbs.3042/

    I have just managed to accomplish what I wanted to do using the xen:callback function. Here's what the andy_headerthumbs template looks like:

    Code:
    <xen:require css="andy_headerthumbs.css" />
    
    <xen:set var="$headerThumbs1"><xen:callback class="Andy_HeaderThumbs_Index" method="getHtml1"></xen:callback></xen:set>
    
    <xen:set var="$headerThumbs2"><xen:callback class="Andy_HeaderThumbs_Index" method="getHtml2"></xen:callback></xen:set>
    
    <xen:set var="$headerThumbs3"><xen:callback class="Andy_HeaderThumbs_Index" method="getHtml3"></xen:callback></xen:set>
    
    <table class="headerthumbs_table">
    <tr>
    <td class="headerthumbs_image">
        <a href="{xen:link {$headerThumbs1}}"><img src="{xen:link '../misc/headerthumbs0.jpg?{$serverTime}'}"></a>
    </td>
    <td class="headerthumbs_image">
        <a href="{xen:link {$headerThumbs2}}"><img src="{xen:link '../misc/headerthumbs1.jpg?{$serverTime}'}"></a>
    </td>
    <td class="headerthumbs_image">
        <a href="{xen:link {$headerThumbs3}}"><img src="{xen:link '../misc/headerthumbs2.jpg?{$serverTime}'}"></a>
    </td>
    </tr>
    </table>
    
    The andy_headerthumbs template is being called by an include from the logo_block template.

    Is there a better way to add variables to the logo_block template?
     
    Last edited: Nov 9, 2014
  7. AndyB

    AndyB Well-Known Member

    I have never used template hooks.
     
  8. Syndol

    Syndol Guest

    A callback is probably better as I do believe hooks are supposed to be phased out at some point. So if you got it working, I'd stick to what you have (y)
     
    AndyB likes this.

Share This Page