Log in

View Full Version : a bit of php help



VistaBoy
30-09-2008, 12:56 PM
Okay i got this issue were i can use php in the .tpl file like <?php if blah bla ?> but when it comes to doing my {if:logged} it does not work it show nothing like {if:logged} was not in the tpl ???

heres my code.


class Page {
var $page;

function page ( $file )
{
$fd = fopen($file, 'rw');
$buffer = fread($fd, filesize($file));
fclose($fd);
$this->page = $buffer;
}

function replace_tags ( $tags = array ( ) )
{
if ( sizeof( $tags ) > 0 )
{
foreach ( $tags as $tag => $data )
{
$this->page = str_replace ( "{" . $tag . "}", $data, $this->page );
}

$this->page = str_replace("{if:logged}", "<?php if ($hello == 'yes') { ?>", $this->page);
$this->page = str_replace("{/if}", "<?php } ?>", $this->page);
}
else
{
die("No tags designated for replacement.");
}
}

function output ( )
{
echo $this->page;
}

}

VistaBoy
02-10-2008, 12:27 AM
Okay i found out when i right click on the page and view page source it shows the php code its self in a purple color.... how can i make it so it will run that php and not just show it in the page source in purple and it does it even if you put the php right into the .tpl now :S

Excellent2
02-10-2008, 01:24 PM
Okay i found out when i right click on the page and view page source it shows the php code its self in a purple color.... how can i make it so it will run that php and not just show it in the page source in purple and it does it even if you put the php right into the .tpl now :SThe file has to be .php if you have php inside it I think.

Source
02-10-2008, 02:22 PM
You idiot excellent ^_^, you should of said that you were using smarty template engine in your post VistaBoy. Unfortuantly I hate smarty so I cannot help you with this issue.

You might not be using smarty, but tpl is the common extension name for the templates smarty uses.

Invent
02-10-2008, 03:06 PM
I use tpl for my own custom templating system, lol. So I don't think it's smarty.

Oh and VistaBoy, if you want to run the PHP, I'm sure you'll need to use eval().

Source
02-10-2008, 03:09 PM
It just seems like a weird extension to use for a template outside of smarty from my point of view as I have always known tpl to be smarty. Every man to his own though.

Invent
02-10-2008, 03:11 PM
'tpl' is commonly known as a short term for template, thus why smarty use it as well as lots of other scripts/systems.

Source
02-10-2008, 03:13 PM
I'm not arguing that at all, im just saying "from my point of view".

Invent
02-10-2008, 03:14 PM
No no, I know :P I'm just saying :P

Source
02-10-2008, 03:16 PM
tbh you know nothing, get out of the internetz!!!!

[/sarcasm]

Tomm
02-10-2008, 03:54 PM
Although I don't know why you just don't use smarty. Its infinitely more powerful that something you could create with limited time and resources.

VistaBoy
03-10-2008, 12:23 AM
Okay i do not know were you got that i was using smarty from -.- any whys i give up on this **** i am going to use smarty now :P as making a custom template system is why to dam hard....

Tomm
03-10-2008, 06:39 PM
http://www.smarty.net/

Okay i do not know were you got that i was using smarty from -.- any whys i give up on this **** i am going to use smarty now :P as making a custom template system is why to dam hard....

Want to hide these adverts? Register an account for free!