How Call an PHP function in HTML pages of template?

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
alexlupoz
Registered User
Posts: 3
Joined: Sat Feb 24, 2018 9:08 pm

How Call an PHP function in HTML pages of template?

Post by alexlupoz »

Hi, everyone!

How can I call an PHP function in an place of HTML page from template? (overal_header.html, per example) :?

Sorry by my ugly english, I'm from Brazil.

Thanks 'n' hugs, friends :D

EDIT:

Per example: I have the page "test.php" where have the function:

Code: Select all

<?php
echo "phrase";
?>
I wish to show this result in a place of the HTML page. In the original PHP have "{USERNAME}". I need use constants to show the result from the PHP page? If yes, how can I do?
User avatar
thecoalman
Community Team Member
Community Team Member
Posts: 5876
Joined: Wed Dec 22, 2004 3:52 am
Location: Pennsylvania, U.S.A.
Contact:

Re: How Call an PHP function in HTML pages of template?

Post by thecoalman »

Under secutity settings enable PHP in templates. One thing to be aware of is your PHP code can be exposed because the template can be requested directly and it is sent plain text.

{USERNAME}

In functions.php you'll find a giant array near the bottom. Around line 4340...

Code: Select all

	// The following assigns all _common_ variables that may be used at any point in a template.
	$template->assign_vars(array(
		'SITENAME'						=> $config['sitename'],
		'SITE_DESCRIPTION'				=> $config['site_desc'],
		'PAGE_TITLE'					=> $page_title,


You can add your own there if you want it available in all templates. viewtopic.php, viewforum.php and other files have additional arrays also found near the bottom.
“Results! Why, man, I have gotten a lot of results! I have found several thousand things that won’t work.”

Attributed - Thomas Edison
User avatar
3Di
I've Been Banned!
Posts: 17538
Joined: Mon Apr 04, 2005 11:09 pm
Location: I'm with Ukraine 🇺🇦
Name: Marco
Contact:

Re: How Call an PHP function in HTML pages of template?

Post by 3Di »

Questions like this should be posted in the Custom Coding forum, created on purpose. :geek:

Anyway... including PHP in a template is not really suggested, but you can also try:

Code: Select all

<!-- PHP -->
	echo "phrase";
<!-- ENDPHP -->
🆓 Free support for our extensions also provided here: phpBB Studio
🚀 Looking for a specific feature or alternative option? We will rock you!
Please PM me only to request paid works. Thx. Buy me a coffee -> Image
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
Post Reply

Return to “phpBB Custom Coding”