Forum Moderators: coopster

Message Too Old, No Replies

including php in tpl files

         

surrealillusions

12:40 pm on Jan 15, 2008 (gmt 0)

10+ Year Member



I'm (trying to) use this template engine -
[webmasterworld.com...]

However, i want to be able to include a config file on top of the template that includes some variables for various bits on the other pages, that are sometimes repeated on each page but not every page. Like the title for example, some pages have similiar titles, some dont. I'd like to be able to have the similiar title bit as a variable, and then stick that in each page in the title bit, where it hopefully echos out on the page. Does that actually make any sense whatsoever? :P

However, when i try this, it doesn't work, all i see in the title in the browser is

$pagetitle blah blah blah

and on the top of the page in the source code is the php include for the config file
<?php
include ('config.php');
?>

Same goes for any other php in the template, such as a data stamp, it doesn't display, but yet the php code is in the source code

Why is this doing this and is there anyway around this?

thanks

:)

mattclayb

2:19 pm on Jan 15, 2008 (gmt 0)

10+ Year Member



if you want to pass variables from or to an 'included' script, you need to use require instead, eg -

<?php
require ('config.php');
?>

jatar_k

2:33 pm on Jan 15, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



what extension does the file doing the including have? I am assuming that file extension is not configured to parse php, hence the php code in the view source

>> if you want to pass variables from or to an 'included' script, you need to use require instead

my apologies but that is not true, include and require work the same way except for how they fail

[php.net...]

The documentation below also applies to require(). The two constructs are identical in every way except how they handle failure. They both produce a Warning, but require() results in a Fatal Error. In other words, use require() if you want a missing file to halt processing of the page. include() does not behave this way, the script will continue regardless.

surrealillusions

3:41 pm on Jan 15, 2008 (gmt 0)

10+ Year Member



all the files are .php, except the template obviously which is .tpl

And thats also how i believe include and require work, so i dont think it will solve the problem.

:)

jatar_k

10:44 pm on Jan 15, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



if it's showing up in the 'view source' in your browser then they aren't getting parsed

unless that wasn't what this meant

"but yet the php code is in the source code"

surrealillusions

10:45 pm on Jan 15, 2008 (gmt 0)

10+ Year Member



ok..so why aren't they getting parsed? And how do i get them to work?

:)