Connecting Tech Pros Worldwide Forums | Help | Site Map

<%something%> in html templates

Phil Latio
Guest
 
Posts: n/a
#1: Jul 17 '05
I have a number of basic PHP books but they don't cover passing variables
into an HTML template which is called into a PHP script. (I am trying to
keep the mark-up and the execution code seperate.)

I have seen <%something%> in an html template page but I am trying to work
out how this value is passed.

What is this process called? I am sure there must be a lot of online
tutorials covering this but I don't seem to be entering the correct search
criteria. If I can create just a simply one, then I will be able understand
what is happening.

Thanks in advance of any help or useful links.

Cheers

Phil

(ps. apologies if you spotted this erroneously posted in alt.php.sql earlier
this afternoon.)





smilesinblues@gmail.com
Guest
 
Posts: n/a
#2: Jul 17 '05

re: <%something%> in html templates


Hi,
I have not seen your code but there are 4 very popular methods of
passing values from one page to the other.

1. $_GET['varname'];
2. $_POST['varname'];
3. $_SESSION['varname'];
4. $_COOKIES['varname'];

so you have to spot these and then search for it.

I strongly feel that in your case it will be GET or POST as they are
basic and SESSION and COOKIES are a little advanced.

Hope this helps,
Bye

BKDotCom
Guest
 
Posts: n/a
#3: Jul 17 '05

re: <%something%> in html templates


In a nutshell, a script will open this template file and do a search
and replace.
So, "parsed", rather than "passed" might be a better word to describe
what's happening.

Malcolm Dew-Jones
Guest
 
Posts: n/a
#4: Jul 17 '05

re: <%something%> in html templates


BKDotCom (bkfake-google@yahoo.com) wrote:
: In a nutshell, a script will open this template file and do a search
: and replace.
: So, "parsed", rather than "passed" might be a better word to describe
: what's happening.

google: php template


--

This space not for rent.
deja@2404.co.uk
Guest
 
Posts: n/a
#5: Jul 17 '05

re: <%something%> in html templates


Hmm.. not sure exactly what it is you've seen. There are a number of
templating systems out there like Smarty (http://smarty.php.net) or
PEARs Template_IT (http://pear.php.net/package/HTML_Template_IT). In
most templating systems, you set the variables in the page code then
call the template when you are ready to display:

<?
// this is example code - not specific to anything
$template = new Template("/path/to/template.tpl");
$foo = "Hello";
$template->set_value("foo", $foo);
$template->display();
?>

and the template would contain something like this:

<html>
<body>
<strong>{foo}</strong>
</body>
</html>

The other thing you may be thinking of is just outputting php variables
within html. For example, you could have a script like this:

<?
$foo = "hello";
include("template.php");
?>

template.php:
<html>
<body>
<strong><?=$foo?>
</body>
</html>

<?=$variable?> prints the contents of the variable.

The <% .. %> are tranditional ASP tags but i know that some template
systems are configured to use them.

Sorry for the vauge rambling - i hope it helps :0)

Steve

madmaster
Guest
 
Posts: n/a
#6: Jul 17 '05

re: <%something%> in html templates


In most cases it is done in a html file where **** (some string) is
replaced with your variable. If it is a simple one the strreplace is
enough, but for more complicated cases preg_* and ereg_* would be
necessary.

See some simple examples of these functions in php.net's manual (preg*
& ereg*) to get the idea of the realiztion of a template system.

Best regards.

Closed Thread