Help with Template.assign_var

Need some custom code changes to the phpBB core simple enough that you feel doesn't require an extension? Then post your request here so that community members can provide some assistance.

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Post Reply
techfreaktwo
Registered User
Posts: 3
Joined: Thu Jan 11, 2018 9:05 am

Help with Template.assign_var

Post by techfreaktwo » Thu Jan 11, 2018 9:29 am

Support Request Template
What version of phpBB are you using? phpBB 3.2.1
What is your board's URL? http://localhost
Who do you host your board with? Self
How did you install your board? I used the download package from phpBB.com
What is the most recent action performed on your board? Fresh Install
Is registration required to reproduce this issue? No
Do you have any MODs installed? No
Do you have any extensions installed? Yes
What extensions do you have installed? Not related to an extension
What styles do you currently have installed? prosilver
What language(s) is your board currently using? english
Which database type/version are you using? MySQL 5
What is your level of experience? New to PHP but not phpBB
What actions did you take (updating your board; installing a MOD, style or extension; etc.) prior to this problem becoming noticeable? Trying to do an SQL query to pull the contents of a post into a variable and then sending that to the template to be displayed.
Please describe your problem. cant get the information to be displayed.
Generated by SRT Generator


Here is the code I have in ucp.php

Code: Select all

		
		$sql = 'SELECT post_text FROM phpbb_posts WHERE post_id = 12';
		$result = $db->sql_query($sql);

		$template->assign_var('S_APP_REQUIREMENTS', $result);

		$db->sql_freeresult($result);
		
after these lines

Code: Select all

	case 'register':
		if ($user->data['is_registered'] || isset($_REQUEST['not_agreed']))
		{
			redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
		}

		$module->load('ucp', 'register');
		$module->display($user->lang['REGISTER']);


but before the break for the "register" case.


and here is the code i have in styles\prosilver\template\ucp_agreement.html

Code: Select all


{S_APP_REQUIREMENTS}


as stated above i am trying to get the contents of post_text from post id 12 onto the template. I know this might seem kind of strange but this is what i am trying to do. Currently what I have displays nothing on the page where {S_APP_REQUIREMENTS} is located and post id 12 is not empty btw :P

Any help is greatly appreciated and i hate to ask for help but I wanted to try to be as detailed as possible when asking but if more information is needed please let me know :)


I have used the following sources for information:
Some of my previous experience with PHP, SQL, and phpBB
https://wiki.phpbb.com/Template.assign_var
viewtopic.php?f=71&t=2121571
viewtopic.php?f=71&t=2169238

User avatar
kasimi
Extension Customisations
Extension Customisations
Posts: 2977
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: Help with Template.assign_var

Post by kasimi » Thu Jan 11, 2018 10:27 am

Replace

Code: Select all

$template->assign_var('S_APP_REQUIREMENTS', $result);
with

Code: Select all

$post_text = $db->sql_fetchfield('post_text');
$template->assign_var('S_APP_REQUIREMENTS', $post_text);
and refresh your board cache so that your template changes take effect.

techfreaktwo
Registered User
Posts: 3
Joined: Thu Jan 11, 2018 9:05 am

Re: Help with Template.assign_var

Post by techfreaktwo » Thu Jan 11, 2018 10:45 am

Welp. Tried it exactly how you posted and made sure i cleared the cache on the board and the browser and it did not work.

Not exactly sure why its not working as it appears to make more sense now...

Thanks so much for the help @kasimi

User avatar
kasimi
Extension Customisations
Extension Customisations
Posts: 2977
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: Help with Template.assign_var

Post by kasimi » Thu Jan 11, 2018 10:58 am

The display() method renders the page and sends the reply back to the client. Your code never executes. Move it between load() and display() and it should work.

techfreaktwo
Registered User
Posts: 3
Joined: Thu Jan 11, 2018 9:05 am

Re: Help with Template.assign_var

Post by techfreaktwo » Thu Jan 11, 2018 11:06 am

Awesome!! That worked! Thank you so much!

Post Reply

Return to “phpBB Custom Coding”

Who is online

Users browsing this forum: No registered users and 7 guests