PHP include in a Theme

PHP include in a Theme

by Mary Evans -
Number of replies: 3
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers
I am working on a theme which, if I get it to work, will call from inside the header.html a .php file as a PHP include, where the path for the .php file is...

<?php include $CFG->wwwroot.'/file.php/1/bxslider/text-1.php' ; ?>

However, this isn't working. And yet, if I put the text-1.php in the theme folder and call it in the simple way <?pnp include 'text-.php' ?> it works just fine.

What I'd like to know is why does it work in one location and not the other? Yet all the php books I've read tell me it should work from any directory, providing the path is correct. So I am guessing I'm doing something wrong here. But what???

This is really strange, since I can get images to show up in the header which use the same path eg:

<img src="<?php $CFG->wwwroot ?>/file.php/1/bxslider/image-1.jpg" />

but not...

<?php include $CFG->wwwroot.'/file.php/1/bxslider/text-1.php' ; ?>


Mary



Average of ratings: -
In reply to Mary Evans

Re: PHP include in a Theme

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers
Hi Mary,
Can't see anything wrong with what you've done at first look - but then you have more experience with php than I do anyway! smile
Would it be worth hard coding in the path to try to narrow down whether the problem is in the php getting the wwwroot location or the fact that the file is in a different location? Obviously not as a long term solution but as a step to finding the issue - the other side to you already having tried the file in the theme folder?

Richard
In reply to Richard Oelmann

Re: PHP include in a Theme

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers
Oh! That's a thought! I'll try it and get back to you.

Edit:
It didn't work...so it must be something do with the way Moodle files are passed through the system.

I'll try it outside of Moodle and see if I can get it to work.
Thanks again Richard.

Mary
In reply to Richard Oelmann

Re: PHP include in a Theme

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

I finally fix this. It was the path that was the problem...I had the wrong prefix.

This is how I solved it ...

<?php include ($CFG->dataroot.'/1/bxslider/text-1.php'); ?>

The fact this works is facinating enough for me, it's all I wanted and more!!!

Cheers

Mary