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

Can you register a variable or helper method?

Discussion in 'XenForo Development Discussions' started by Razasharp, Feb 1, 2014.

  1. Razasharp

    Razasharp Well-Known Member

    I'd like to create a helper method and have it available in views (templates) as I will use it a number of times so would prefer to DRY - the code may be added to so it would be best to be able to update it in one place.

    Something like:

    def my_special_forums
      <xen:if is="in_array({$forum.parent_node_id}, array(21, 22, 68, 79)">
        return true
      <xen:else />
        return false
    So then I could use something like this in the templates:

    <xen:if is={$my_special_forums}>
      do this
    (I am not sure if you call helper methods methods or functions, hence my pseudo ruby-xenforo code above)

    If it isn't possible to do it via helpers, can I do it once at the top of a template? Though of course it would be ideal to have this defined once and available to all templates.

Share This Page