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

Inject HTML into custom template with template variables?

Discussion in 'XenForo Development Discussions' started by Liam W, May 9, 2013.

  1. Liam W

    Liam W Well-Known Member

    I have a custom template setup for an addon, which basically contains a select drop down box.

    The options are dynamic, and I though I would be able to stick them in by creating an array of the <option></option> tags in the php, and then adding this to the viewparams and then using <xen:foreach> to loop through the option tags and output them.

    Well, this sort of works - but it doesn't. The outputted text is obviously not intepreted as HTML, and as such the options aren't being added to the drop down.

    Is there any way I could do this?

    (If only there was an <xen:eval> template thingy...)
  2. ManOnDaMoon

    ManOnDaMoon Well-Known Member

    Try {xen:raw $yourHTMLvar}.
    rour, Jake Bunce and Liam W like this.
  3. Liam W

    Liam W Well-Known Member

    Your da best, thanks!
  4. Jeremy

    Jeremy XenForo Moderator Staff Member

    If you're already using a <xen:foreach> in the template, you should just put any HTML in the templates and not in the PHP.
    ManOnDaMoon and Liam W like this.
  5. Liam W

    Liam W Well-Known Member

    True, but I was initially doing it a different way, and it was easier to not change it. I'll do it that way now though :)

    (Also, I didn't think of your way ;))

    Incidentally, is it possible to define custom actions for existing controllers to create a custom route of the existing route?
  6. Jeremy

    Jeremy XenForo Moderator Staff Member

    Yes. Hook into the listener and extend the controller. I believe the listener is load_class_controller.

Share This Page