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

Pass array variable from template to template hook

Discussion in 'XenForo Development Discussions' started by simbolo, Apr 3, 2012.

  1. simbolo

    simbolo Well-Known Member

    What I need to do is pass a variable from a xen:foreach loop to the hook.
    Example:
    "post_edit" includes "attachment_editor" which includes "attachment_editor_attachment"
    I've placed a hook within "attachment_editor_attachment"
    PHP:
    <div class="controls">               
                    <
    input type="button" value="{xen:phrase delete}" class="button smallButton AttachmentDeleter" data-href="{xen:link 'attachments/delete', $attachment}" />
               
                    <
    xen:if is="{$attachment.thumbnailUrl}">
                        <
    input type="button" name="thumb" value="{xen:phrase thumbnail}" class="button smallButton AttachmentInserter" />
                        <
    input type="button" name="image" value="{xen:phrase full_image}" class="button smallButton AttachmentInserter" />
                    </
    xen:if>
                </
    div>
    <
    xen:hook name="tags_editor_attachment" />
    Now in the foreach variable "attachment" is available and I'd like to pass it to the hook. Within my templateHook function it is not in template _params so I'm assuming it's something that I need to set, but not sure how to pass that in.

    If it helps the data I need is the specific attachment id that is currently in scope of the foreach loop.
     
  2. simbolo

    simbolo Well-Known Member

    Check that, figured it out just needed to pass in the variable as a hook param:
    PHP:
    <xen:hook name="tags_editor_attachment"  params="{$attachment}/>
     
  3. simbolo

    simbolo Well-Known Member

    Better:
    PHP:
    <xen:hook name="buzztags_editor_attachment"  params="{xen:array 'attachment={$attachment}'}" />
     

Share This Page