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

Populating a template with data from the database

Discussion in 'XenForo Development Discussions' started by karll, Aug 4, 2013.

  1. karll

    karll Well-Known Member

    I have an add-on with a template that is calling on PHP code. The PHP code fetches some data out of the database and returns this back in an array of a certain format, which the template is using to populate itself. (Well, something like that :))

    What are the requirements on the PHP side of things to make this work? I.e. what kind of directory structure do I need? Any classes I need to extend?

    Also, I was hoping to do this "properly" in terms of MVC considerations ...

    (Background: I have a free add-on which appears to be unsupported, and want to make it work on XF1.2. I'm also hoping to learn something from the exercise.)
     
  2. Jeremy

    Jeremy Well-Known Member

    How are you calling the PHP code? Is there an add-on which fetches data and calls the proper template rendering classes?
     
  3. karll

    karll Well-Known Member

    Looks like it's called by the xen tags in the template? I see lots of xen tags like:
    <xen:if is="{PHP expression here ...}">
    and also
    <xen:foreach loop="$add-on_name" value="$class_name" i="$limit">
    etc.

    Can't say I understand all of it - is there documentation handy anywhere that explains the various xen tags?

    I think so. The fetching of data definitely works. There is a call to the responseView function (inherited from Xenforo_Controller?) somewhere in the code, which I'm guessing will render the populated template?
     
  4. karll

    karll Well-Known Member

    Ah yes: Template Syntax: XenForo Tags
     
  5. Marcus

    Marcus Well-Known Member

    You just need <xen:
    If
    Foreach
    Callback (maybe, i never used it)
     
  6. AndyB

    AndyB Well-Known Member

Share This Page