Get Template Variables

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
Cohaven
Registered User
Posts: 14
Joined: Wed Oct 18, 2017 2:53 pm

Get Template Variables

Post by Cohaven »

Is there any way to get template variables from the \phpbb\template\template $template? I know how to assign variables:

Code: Select all

$this->template->assign_vars(array(
                'USERNAME'   => $display_name,
                'L_CONTACT_USER' => "CONTACT $display_name",
                )
);
but I can't find a way to get the variables that were assigned. Something like:

Code: Select all

$username = $this->template->get_var('USERNAME');
User avatar
kasimi
Former Team Member
Posts: 4900
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: Get Template Variables

Post by kasimi »

For phpBB 3.1.x and 3.2.0 you need to use the @template_context service:

Code: Select all

$username = $this->template_context->get_root_ref()['USERNAME'];
Since phpBB 3.2.1 you can use the @template:

Code: Select all

$username = $this->template->retrieve_var('USERNAME')
Post Reply

Return to “Extension Writers Discussion”