Forum Moderators: coopster

Message Too Old, No Replies

{keywords}

Can't find a reference in the manual

         

bumpaw

4:31 am on Feb 11, 2004 (gmt 0)

10+ Year Member



I'm trying a Newsletter script that has me puzzled. It was written about two years ago. The template for the subscribe is html with what the author calls keywords.

<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.

zollerwagner

7:18 am on Feb 11, 2004 (gmt 0)

10+ Year Member



I don't know about the manual, but my PHP Advanced by Larry Ullman (both his books have helped me a lot) says on p. 51:

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!

bumpaw

2:45 pm on Feb 11, 2004 (gmt 0)

10+ Year Member



I searched the area that you indicated and no bells went off, but this code will probably solve it for a person with more experience than myself.

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);
}

zollerwagner

5:56 pm on Feb 11, 2004 (gmt 0)

10+ Year Member



Then try reading the general info on arrays. That's what you've got there. There are several different ways to create an array.

It's not extremely clear what your question is, though.

ergophobe

8:40 pm on Feb 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




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

bumpaw

12:53 am on Feb 16, 2004 (gmt 0)

10+ Year Member



Tom, I had to abandon that one from EternalMart. After I got it installed the email wouldn't send. There where references on a forum that others also had big trouble getting it to work with PHP 4.3, and that the developer had not responded in a long while. The code was written over two years ago. On a happy note I have the JAX Newsletter working well. It's last version was issued in January 2004.

[edited by: jatar_k at 1:35 am (utc) on Feb. 16, 2004]
[edit reason] delinked [/edit]

bumpaw

4:20 am on Feb 19, 2004 (gmt 0)

10+ Year Member



Sorry if the linking was inappropriate. I'll have to go back to the TOS again. Maybe you could sticky me with the reason it was wrong. My thinking was that since it was OS free and not mine, that it was good and helpful. I think my brain is slowing down.

webadept

7:35 am on Feb 19, 2004 (gmt 0)

10+ Year Member



What I see there is a template .. and you simply need a template function to fill in the blanks.

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

zollerwagner

8:24 am on Feb 19, 2004 (gmt 0)

10+ Year Member



Glenn's right:
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.

bumpaw

12:46 pm on Feb 19, 2004 (gmt 0)

10+ Year Member



Thanks to all for the detailed help. Glenn's detailed explanation is going in my reference file, and I'll be looking for a used copy of Ullman's book. We only have "PHP and MySQL" by Laura Thomson.