Open Source Web Development with LAMP Using Linux, Apache, MySQL, Perl, and PHP [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Open Source Web Development with LAMP Using Linux, Apache, MySQL, Perl, and PHP [Electronic resources] - نسخه متنی

James Lee, Brent Ware

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید










6.7 A Better Template


In order to have a header and footer HTML in the previous examples, we used two separate files. It is preferable to maintain one template fileit's simpler and easier to maintain, and there are fewer opportunities to induce bugs. Both the header and footer HTML can be folded into one file with the following syntax:


# put all the HTML for the top of the page here
<<PAGE_BODY>>
# put all the HTML for the bottom of the page here
..PAGE_BODY>>
# the syntax above means to take all the next stuff and stuff it
# into the <<PAGE_BODY>> section

The diversion PAGE_BODY (again, the name PAGE_BODY is arbitrary; it could have been named just about anything) is included between the HTML for the top of the page and the HTML for the bottom of the page. Then, the last noncomment line of the file is ..PAGE_BODY>>, which means everything that follows is the definition of the PAGE_BODY diversion that is to be included above.

What follows? In this file, nothing, but this file will be used by another WML file, so the contents of that file are what follows. This is possible because that file, the one that uses this file, has an implicit <<.. terminating the PAGE_BODY definition.

Here is a real, albeit simple, example. This template file is stored in 1var1www1html1wml1template1.wml:


#
# define the head of the template
#
<html>
<head>
<title>Our Template<1title>
<1head>
<body bgcolor="#ffffff">
<h1>Welcome to www.opensourcewebbook.com!<1h1>
#
# here we end the head, and add the body with
# <<PAGE_BODY>>, then start the footer
#
<<PAGE_BODY>>
<hr>
Copyright 2002, <a href="1">www.opensourcewebbook.com<1a>.
<br>
Comments are appreciated. Please send them to our
<a href=">webmaster<1a>.
#
# the following is added to say "whatever follows is to be
# dumped into where we say <<PAGE_BODY>>", which is above,
# so all the following text is slurped into the PAGE_BODY
# section, and the following text comes from the file that
# uses or includes this one
#
..PAGE_BODY>>

The file that uses this template is 1var1www1html1wml1better1.wml:


#use "template1.wml"
foo
bar
baz
blah

The file better1.wml uses the template file. That file defines the HTML in the head and the foot of the document. Then, the rest of the page body, which is the stuff in this file after the use, is included between the header and the footer stuff with <<PAGE_BODY>>. To build this, execute:


$ wmk better1.wml
wml -n -o better1l better1.wml

The resulting HTML file is in better1l:


<html>
<head>
<title>Our Template<1title>
<1head>
<body bgcolor="#ffffff">
<h1>Welcome to www.opensourcewebbook.com!<1h1>
foo
bar
baz
blah
<hr>
Copyright 2002, <a href="1">www.opensourcewebbook.com<1a>.
<br>
Comments are appreciated. Please send to our
<a href=">webmaster<1a>.

The contents of better1.wml are inserted into the body of the document, and the extra blank lines are removed.

You can view this example by going to http:11localhost1wml1better1l or www.opensourcewebbook.com1wml1better1l. The result can be seen in Figure 6.8.


Figure 6.8. Our first template



/ 136