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

Read template in PHP

nrep

Well-known member
#1
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? ;)
 

nrep

Well-known member
#3
In a controller you can return $this->responseView('ViewClassName', 'template_name', array('param1'=>1, 'param2'=>2)
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');
 

nrep

Well-known member
#4
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
");
 

Jake B.

Well-known member
#5
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');
Where are you running this from? Somewhere outside XenForo? Or a template hook?
 

nrep

Well-known member
#6
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 :).