Forum Moderators: coopster
<input type="TEXT" size="6" name="emml[email]" value="{EMAIL}">
</font><font size="-1"> </font><font face="Verdana, Arial, Helvetica, sans-serif" size="-1">{DEFAULT_MAILING_LIST}</font></font></td>
The documentation says:
You can modify those template files to your style. When modifying these files, please don't modify text which is embraced with { and }. They are KEYWORDS. If they are modified, strange result may occur.
ETERNALMART
Can anybody give me a clue where to find this usage in the manual? I am wondering if it is deprecated.
conventionally, when programmers use objects with HTML templates, the braces and all capital letters format is used to indicate a replaceable item (e.g.{SIDEBAR}). This is not required by PHP. You could just as easily format (<!--SIDEBAR-->, the end result being that unreplaced elements do not display in the Web browser the way {SIDEBAR} would.
This is in a chapter on object-oriented programming.
I think if you search your files for DEFAULT_MAILING_LIST, you'll find a chunk of code that defines this object (I assume it's an object...).
In the php manual there are a number of listings for object. The most basic may be:
[us4.php.net...]
good luck!
function display_emml_form($msg){
global $tpl_html;
global $emml;
global $emml_script_url;
global $eternalmart;
global $emml_image_url;
global $listid;
$default_mailing_list = get_default_mailing_list();
if(get_magic_quotes_gpc()){
$emml[email] = htmlspecialchars(stripslashes(trim($emml[email])));
}
else{
$emml[email] = htmlspecialchars(trim($emml[email]));
}
if($emml[subscribe] == 'N'){
$subscribe_yes = "";
$subscribe_no = "CHECKED";
}
else{
$subscribe_yes = "CHECKED";
$subscribe_no = "";
}
$tpl_html->assign( array(
"ERR_MSG" => "$msg",
"SCRIPT_URL" => "$emml_script_url",
"EMAIL" => "$emml[email]",
"DEFAULT_MAILING_LIST" => "$default_mailing_list",
"SUBSCRIBE_YES" => "$subscribe_yes",
"SUBSCRIBE_NO" => "$subscribe_no",
"COPYRIGHT" => "$eternalmart",
"IMAGE_URL" => "$emml_image_url",
"LISTID" => "$listid"
));
$tpl_html->parse(TPL_EMML_FORM, "tpl_emml_form");
$emml_form = $tpl_html->fetch(TPL_EMML_FORM);
display_html($emml_form);
}
where to find this usage in the manual?
I think the key question here is "What manual?" This is just a convention that the creator of the application has used. Whether or not it is deprecated will be up to whoever created the ap.
No doubt, the application parses the template and inserts the necessary code when it comes across a keyword enclosed within curly braces. The corollary to the notice you posted about not changing anything within the brackets is that if you have a page where you want it to say "The template defines the {DEFAULT_E_MAIL_ADDRESS} in some other file" you may also get strange results.
Tom
[edited by: jatar_k at 1:35 am (utc) on Feb. 16, 2004]
[edit reason] delinked [/edit]
A template setup is in two forms, a HTML file, and a funtion which sets up that HTML file with the needed information, in your case, the email address and various other needs.
The {EMAIL} is the constant, and your function, working with a Object, more than likely, would search the template for KEYs like those. Once it found one, it would then check the Object to see what it was suppose to do with that KEY. You aren't going to find this in a PHP manual, because it is a coding techniqe (Although there is a book called Advance PHP Programming .. I remember it having a orage and black cover, or something like that, I'm sure I could find it if you really need the issue.)
The class objects can be really simple, and I happen to have a simple one here I picked up from some place.
class HtmlTemplate {// Set the attributes.
var $template;
var $html;
var $parameters = array();
function HtmlTemplate ($template) { // This function sets which template will be used.
$this->template = $template;
$this->html = implode ("", (file($this->template))); // Read the template into an array, then create a string.
}
function SetParameter ($variable, $value) { // This function sets the particular values.
$this->parameters[$variable] = $value;
}
function CreatePage () { // This function does the bulk of the work.
foreach ($this->parameters as $key => $value) { // Loop through all the parameters and set the variables to values.
$template_name = '[% ' . $key . ' %]';
$this->html = str_replace ($template_name, $value, $this->html);
}
echo $this->html;
}
}
So, once you have that, you set up the object in your function of main body code with something like this.
# this is the part that sets the object
# the $ORDERS_DIR is a previously set constant value
#and basically all we are doing here is telling itware the template page
# is located at.
$bodyform = new HtmlTemplate($ORDERS_DIR . "/templates/order_detail_page.inc");# once the templage is set to the
#object class, we now set values to our
# keys. This template worked off a [% %] setup
# where yours is using a { } seutp to tell the objec that
# "between these brackets is the KEY I want you to look for"
# Then you write this
$bodyform->SetParameter("EMAIL", $UserEmail);
#simple. Now when all your KEYs are fullfilled,
#you tell the object you are done and ready to
# send to browser
$bodyform->CreatePage();
And really that's all there is too it. The reason you would use this type of setup is for a seperation between church and state, or rather, the coder and the designer. Using a Template system like this, allows the designer to do just about anything they wanted to the template HTML files, as long as they put in the proper KEYs, and as long as they did so, they would not have to bother the coder, with changes or updates to her code, thus allowing her to move forward in whatever it is she is doing.
This lends itself very well to CSS driven sites, which what to change periodically, with page design or page layout, but still want the same functions.
Hope the helps you, and if you have any questions, feel free to drop me a sticky or whatever it is we can do around here to contact one another.
Glenn Hefley
You aren't going to find this in a PHP manual, because it is a coding techniqe (Although there is a book called Advance PHP Programming .. I remember it having a orage and black cover, or something like that, I'm sure I could find it if you really need the issue.)
I think that's Larry Ullman's book, Php Advanced for the World Wide Web. It's got a very detailed section on using objects.