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 » Sat Feb 24, 2018 9:14 pm

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: 2625
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 » Sun Feb 25, 2018 1:01 am

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.

User avatar
3Di
Registered User
Posts: 12557
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

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

Post by 3Di » Sun Feb 25, 2018 1:26 am

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 -->
Want to compensate me for my interest? Donate
Please PM me only to request paid works. Thx.
Extensions, Scripts, MOD porting, Update/Upgrades
My development's activity º PhpStorm's proud user

Post Reply

Return to “phpBB Custom Coding”

Who is online

Users browsing this forum: JimA and 7 guests