471,594 Members | 1,656 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,594 software developers and data experts.

<%something%> in html templates

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.



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

Jul 17 '05 #1
5 1414
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,

Jul 17 '05 #2
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
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
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);

and the template would contain something like this:


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";


<?=$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)


Jul 17 '05 #5
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

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.

Similar topics

4 posts views Thread by Christopher Pisz | last post: by
5 posts views Thread by Osamede Zhang | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Anwar ali | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.