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

Read template in PHP

Discussion in 'XenForo Development Discussions' started by nrep, Mar 3, 2015.

  1. nrep

    nrep Well-Known Member

    I'm working on an addon and I'm able to read variables that I've set in the options page like so:

    $title= XenForo_Application::get('options')->addon_title;

    However, I can't figure out how to read a template. Is there something simple that I'm missing? I've found out how to add one, but I can't see how to read it :oops:.

    Can anyone help this idiot please? ;)
     
  2. Jake B.

    Jake B. Well-Known Member

    In a controller you can return $this->responseView('ViewClassName', 'template_name', array('param1'=>1, 'param2'=>2)
     
    Cyb3r likes this.
  3. nrep

    nrep Well-Known Member

    Thanks, I tried that but I get this error : "Using $this when not in object context..."

    This is the context:

    $newsletterHTML = $this->responseView('Newsletter_Callback_Generate', 'newsletter_email_template');
     
  4. nrep

    nrep Well-Known Member

    Here's how I've done it for now, just using MySQL:


    $db = XenForo_Application::get('db');


    $newsletterRAW = $db->fetchOne("
    SELECT template
    FROM xf_template
    WHERE title = 'newsletter_email_template'
    LIMIT 1
    ");
     
  5. Jake B.

    Jake B. Well-Known Member

    Where are you running this from? Somewhere outside XenForo? Or a template hook?
     
  6. nrep

    nrep Well-Known Member

    It's inside a callback from an addon I'm using (not sure if that's the correct terminology). The MySQL query works fine though, so that should do the trick :).
     

Share This Page