By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,406 Members | 1,504 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,406 IT Pros & Developers. It's quick & easy.

<%something%> in html templates

P: n/a
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.)


Jul 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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

Jul 17 '05 #2

P: n/a
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.

Jul 17 '05 #3

P: n/a
BKDotCom (bk***********@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.
Jul 17 '05 #4

P: n/a
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

Jul 17 '05 #5

P: n/a
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.

Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.