checking for include in 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
Nick225
Registered User
Posts: 131
Joined: Sat Nov 24, 2018 7:48 pm

checking for include in Template

Post by Nick225 »

<!-- INCLUDEPHP somefile.php -->
How do we check for the existence of the file?
something like
<!-- if EXISTS somefile.php --><!-- INCLUDEPHP somefile.php --> <!-- ENDIF --->
Looking in the tutorials but can't find the right syntax.
User avatar
AlfredoRamos
Recognised Extension Developer
Posts: 1302
Joined: Wed Dec 25, 2013 9:06 pm
Location: /dev/null
Name: Alfredo
Contact:

Re: checking for include in Template

Post by AlfredoRamos »

Is there any specific reason to not use a PHP file to check the existence of a file? Why INCLUDEPHP?

Not the same, but in Twig you can ignore the inclusion if the file does not exist:

Code: Select all

{% include '@vendor_extension/file.html' ignore missing %}
In PHP, you can check if a file exist with something like:

Code: Select all

$file = $filesystem->realpath(__DIR__ . '/path/file.html');

if ($filesystem->is_readable($file))
{
	// File exist, and is readable
}
Some of my phpBB extensions:
:chart_with_upwards_trend: SEO Metadata | Image Markdown | :shield: hCaptcha
:trophy: Check out all my validated extensions :trophy:

:penguin: Arch Linux user | Linux Boards :penguin:
Nick225
Registered User
Posts: 131
Joined: Sat Nov 24, 2018 7:48 pm

Re: checking for include in Template

Post by Nick225 »

Thanks for the quick reply.. I had just implemented it using twig. Got it in php. Wanted to stay with the template syntax to get used to it.
I had some issues with the path in custom subfolders.
User avatar
canonknipser
Registered User
Posts: 2096
Joined: Thu Sep 08, 2011 4:16 am
Location: Germany
Name: Frank Jakobs
Contact:

Re: checking for include in Template

Post by canonknipser »

Nick225 wrote: Tue Dec 11, 2018 3:25 am Wanted to stay with the template syntax to get used to it.
So, go for twig, because the old style phpBB template syntax is only there for backwards compatibility. Internally all is converted to twig.
Greetings, Frank
phpbb.de support team member
English is not my native language - no support via PM or mail
New arrival - Extensions and scripts for phpBB
User avatar
Lumpy Burgertushie
Registered User
Posts: 69224
Joined: Mon May 02, 2005 3:11 am
Contact:

Re: checking for include in Template

Post by Lumpy Burgertushie »

If I remember correctly, if the file is not there it will simply ignore the include statement. that would show you that the file is not there.


robert
Premium phpBB 3.3 Styles by PlanetStyles.net

I am pleased to announce that I have completed the first item on my bucket list. I have the bucket.
Nick225
Registered User
Posts: 131
Joined: Sat Nov 24, 2018 7:48 pm

Re: checking for include in Template

Post by Nick225 »

Thanks you guys...
Post Reply

Return to “phpBB Custom Coding”