Disclaimer; I'm no expert but I'll toss a couple ideas at you. Because it
seems that part of your concern is httpd.conf, I'll attach my severly
incomplete tutorial document to this reply. The document is marked up for
DocBook so you'll have to sort your way through that code. That aside, I
think the tutorial should give you some solid information on httpd.conf
and building hosts within Midgard. Have a look at it and maybe take it
from there.
> I installed midgard from rpms and everything's gone just fine, till the
> time I tried to access the admin and example site...
> when I try localhost:8101 I get a 404:Not found error. I looked in the
> FAQ, but everything seems to be OK
> (MidgardRootFile points to an existing file, but I don't know what
> permisions to set on it - I even tried 777 - all permisions for all
> users and is still won't work)
> If I try to access the example site (localhost:8099) I get the same page
> as with the normal (80) port (the homepage)
> I don't know what else could I do
> In the server error log I get a notice like that: Host record for
> localhost:80 not found
> In addition, when I start my apache web server, I get the following in
> the error log:
> VirtualHost 127.0.0.1:8099 - mixing * and non-* ports with a
> NameVirtualHost address is not supported, proceeding with undefined
> results
> and the same message for 8101 port...
>
>
> --
> This is The Midgard Project's mailing list. For more information,
> please visit the project's web site at http://www.midgard-project.org
>
> To unsubscribe the list, send an empty email message to address
> [EMAIL PROTECTED]
>
>
<!DOCTYPE ARTICLE PUBLIC "-//Davenport//DTD DocBook V3.0//EN">
<article>
<artheader>
<title>Midgard Tutorial</title>
<authorgroup id="authors">
<author>
<firstname>Henri</firstname><surname>Bergius</surname>
</author>
<author>
<firstname>Emiliano</firstname><surname>Heyns</surname>
</author>
<author>
<firstname>Ron</firstname><surname>Parker</surname>
</author>
</authorgroup>
</artheader>
<sect1>
<title>Building and Managing a site
</title>
<!--Intro-->
<simpara>
Site Plan:
</simpara>
<simpara>
This tutorial builds an entertainment website (Host) that is the home
for many band websites and many services; news, product, yahoo style
internet portal scripts etc. Subpages belonging to the Host Root
(vmucentertainment) share the Root style; these include, the news and
Midhoo portal pages. While band Subpages are treated as independent
entities because each one requires its own layout (Style).
</simpara>
<simpara>
While vmucentertainment pages and topic trees are owned by one group
(VMUC Admins), band page topic trees are owned by their own groups.
Members of the band groups are responsible for the development
and maintanance of their respective Topic tree and it's sub-documents.
Consequently, our sample band Madkings must have its own "group" and
"users" who inherit the groups write privelages. In this
example the Midgard administrator assigns ownership of the Madkings
topic tree to the group "madgroup." Thus enabling user write privelages
which cascade through all topics and articles that are owned by
madgroup.
</simpara>
<simpara>
The application of a Style to "pages" is configured within the Host
Administration interface. The Root Page for our site is
vmucentertainment.com. Because the site is home to many bands, we
create a subpage of root named "bands" which in turn is the "parent"
for subsequent band pages including the MadKings pages.[0]
</simpara>
<simpara>
Additionally, we'll explore the Midgard functions and php scripts that
handle the sites content management features. You're encouraged to use
the included code and graphics within your own projects.
</simpara>
<simpara>
The tutorial includes Emiliano Heyns', Midgard developer and unix system
administrator, Midhoo php script which serves as a study in dynamamic
content handling. Additionaly, it borrows much of it's content
management from Henri Bergius', Midgard Project Manager, VMUC site.
</simpara>
<simpara>
If this tutorial is your first attempt at using Midgard, you
can to refer to the Introduction section of the Manual for an
explanation of the four administration tools that are
used for creating and serving Midgard web applications; Content
Administration, Host Administration, Layout Administration and
Group Administration.
</simpara>
<simpara>
Our first challange is to build the host. We begin by configuring the
Apache httpd.conf file and then build the Host configuration within
Midgard. Upon successfully testing the host, we'll study the relationship
between Midagrd and Apache and conclude that section with an examinination
of the Midgard process for constructing sites.
</simpara>
<!--Intro End-->
<!--HTTP Begin-->
<sect1>
<title>Apache: httpd.conf</title>
<simpara>
This example doesn't attempt to denote the best way to configure
Apache for VirtualHosts because every Apache server is configured to
address it's unique challenges. We're demonstrating a solution where
four sites are served from one domain by using VirtualHosts and
assigning unique ports to each VirtualHost configuration.
</simpara>
<programlisting>
<simpara>
Port: The port the server listens to. For ports under 1023,
you will need httpd to be run as root initially.
</simpara>
<simpara>
<itemizedlist>
<listitem>
Listen 80
</listitem>
<listitem>
Listen 8099
</listitem>
<listitem>
Listen 8101
</listitem>
<listitem>
Listen 8102
</listitem>
</itemizedlist>
</simpara>
<simpara>
NameVirtualHost 192.168.1.1:80
</simpara>
<simpara>
<VirtualHost 192.168.1.1:80>
ServerName www.vmucentertainment.com
Port 80
</VirtualHost>
</simpara>
<simpara>
<VirtualHost 192.168.1.1:8099>
ServerName www.vmucentertainment.com
Port 8099
</VirtualHost>
</simpara>
<simpara>
<VirtualHost 192.168.1.1:8101>
ServerName www.vmucentertainment.com
Port 8101
</VirtualHost>
</simpara>
<simpara>
<VirtualHost 192.168.1.2:8102>
ServerName www.vmucentertainment.com
Port 8102
</VirtualHost>
</simpara>
</programlisting>
<simpara>
When combined with the Midgard default configuration our VirtualHost
entries produce the Midgard VMUC demonstration site in port 8099,
8101 is the administration site, 8102 is our tutorial site while 80
continues to serve your current default Apache site.
</simapara>
</sect1>
<!--HTTP End-->
<!--Host Begin-->
<sect1>
<title>Midgard: Building the Host</title>
<simpara>
Having configured Apache, our next step is to build the Midgard Host.
We specify the Fully Qualified Domain Name (FQDN) within the Name
field. Our VirtualHost and port map configuration is designed with
the assumption that you're serving a non-Midgard site which is mapped
to port 80. Because we're developing and testing a Midgard version of
vmucentertainment.com we map it to port 8102 so the non-Midgard site
continues serving while we develope our new site. When the new site
is presentable, you have the option of mapping its port to 80 or
assigning the Midgard catch-all 0.
</simpara>
<simpara>
Our httpd.conf file maps vmucentertainment.com to ports 80, 8099,
8101 and 8102. Our strategy is to use vmucentertainment.com:8102 as
the development port while 8099 is the VMUC site and 8101 is the
Midgard Amdinistration site. When a Midgard host is mapped to 0 it
answers all calls to its name. Consequently, it isn't necesarry to
restart Apache when switching the development site port map from
8102 to 0. Treating the new Host as the default site is simply a
matter of changing it's port assignment from 8102 to 0. If we mark
the site off-line, the site mapped to port 80 is served when a client
requests vmucentertainment.com
</simpara>
<simpara>
You can grant write permissions to groups for the purpose of
allowing group members to assume responsibility for the management
of content within specific branches of your Host data tree.
Group and group membership is designed within the Group Administration
interface while the ownership of specific branches of data is
configured within the Content Administration tool. Obviously the
Midgard administrator account mandates that membership
be treated with the utmost consideration. The Administration account
is akin to "root" in the unix security scheme. The Midgard
Administration account enjoys write privelages which cascade
throughout the entire Midgard data tree. While specific groups
exersize write priveleges that are constrained within the data
branches which the group has recieved ownership of. A reasonable
strategy is to consider creating a new group that's assigned
ownership of your new host. You should never assign membership to
the Midgard Administration account unless that person requires
responsibility for the entire Midgard data tree.
</simpara>
<simpara>
In the case of vmucentertainment.com ownership is assigned to the
group "VMUC Admins" which is the group that owns the host VMUC that
ships as a configured and running host with the Midgard application.
Select the style we created in step one to be used for this host and
finally in this case we're mapping to the VMUC Root page that we
built earlier.
</simpara>
<simpara>
When mod_midgard is active it hooks a filter into Apache
that checks every request and determines if it's targeted
for a Midgard-enabled site. If a mapping is found, the corresponding
page and style elements are fetched from the database and the Apache
server is pointed to the file "midgard-root.php3" as instructed by
the "MidgardRootfile" directive. Afterwards the Midgard-PHP
content handler is invoked and reads our Root file and starts
generating the page from the style elements.
</simpara>
<simpara>
The translation handler searches for a Midgard host record
that matches the following criteria:
</simpara>
<itemizedlist>
<listitem>
<simpara>
Apache ServerName (ap_get_server_name) equals the host
record name
</simpara>
</listitem>
<listitem>
<simpara>
The host record port is either 0 (any) or equals the
Apache port (ap_get_server_port)
</simpara>
</listitem>
<listitem>
<simpara>
The host is online (online bit is set) and the URI maps to an
active page record which is either "/" or a sub of "/."
</simpara>
</listitem>
</itemizedlist>
<simpara>
If no matching host is found, then the handler declines to
translate the request and standard Apache functionality is
resumed.
</simpara>
<simpara>
If you want to experiment with different Midgard hosts, you
should first use the Host administration tool to set a host name and
port to some proper values and set the host online. Then use
httpd.conf to tell Apache to recognize that address. For example:
</simpara>
<simpara>
From the your Midgard Administration interface, navigate to the Host
Administration interface and then:
</simpara>
<itemizedlist>
<listitem>
Host: Admininistration interface.
</listitem>
<listitem>
New: host www.vmucentertainment.com
</listitem>
<listitem>
Name: 8102
</listitem>
<listitem>
Status: online
</listitem>
<listitem>
Atuthentication: not required
</listitem>
<listitem>
Owner: administators
</listitem>
<listitem>
Style: Midgard Admin Site 1.0
</listitem>
<listitem>
Root page: new root page
</listitem>
</itemizedlist>
<simpara>
Upon requesting the host www.vmucentertainment.com:8102 Midgard will
serve a page that states "It worked." Now we'll build the style for
our site.
</simpara>
</sect1>
<!--Host End-->
<!--Site Building Begin-->
<title>Site Construction, Interaction Between Midgard, Apache</title>
<simpara>
We've defined a plan for vmucentertainment and built the host
configurations within the Apache httpd.conf file and the Midgard Host
Administration interface. Before we proceede with the next step of
building a toplevel style, we'll examine how Midgard interacts with Apache
when determining if a request is for a Midgard host. We'll also
study how Midgard processes style and content elements when constructing
a site.
</simpara>
<simpara>
The standard HTTP process requests three important pieces of
information:
</simpara>
<itemizedlist>
hostname
portnumber
URI within the host
</itemizedlist>
<simpara>
Midgard determines if an HTTP request is for a host that it manages by
matching the requested hostnames and port numbers to those within its
database. This is possible because Midgard hooks a filter into Apache
which examines every http request. When Midgard finds port 0 specified
within its database it considers that site to have precedence over the
httpd.conf port 80 site and procedes to serve the Midgard site. Also, the
prefix defined in the database must match the start of the URI, and the
host must be marked online.
</simpara>
<simpara>
When a user doesn't specify a port number their browser defaults to
requesting port 80. When multiple hosts exist with the same
name Midgard picks the one which most specifically defines the portnumber.
In the Apache httpd.conf configuration file we've specified
vmucentertainment.com as the default port 80 Host. Consequently, a
request for www.vmucentertainment.com:80 produces an entirely different
site than a request for www.vmucentertainment.com:8101 which in our
configuration is the Midgard admininstration site.
</simpara>
<simpara>
Having found a host, Midgard proceeds by walking through the specified
URI until it finds the requested page record. Upon locating the record it
begins processing the midgard-root.php3 script which includes an element
named ROOT that normally consists of a nested set of elements. A
hierarchicaly ordered process of referencing and expanding elements
begins with ROOT and continues until every style element within ROOT is
expanded and replaced with the contents that each element references.
Note that the elements of VMUC are head and body.
</simpara>
<programlisting>
<simpara>
<html>
<[head]>
<[body]>
</html>
</simpara>
</programlisting>
<simpara>
The VMUC head element is comprised of a set of nested elements. Each one
of the elements contains a script that performs its respective duty.
<simpara>
<programlisting>
<simpara>
<head>
<[head-title]>
<[head-made]>
<[head-author]>
<[head-generator]>
<[head-description]>
<[head-style]>
</head>
</simpara>
</programlisting>
<simpara>
An examination of <[head-title]> reveals a php script that Emile wants to
describe. :)
</simpara>
<programlisting>
<simpara>
<title><?
if ($article) {
?>VMUC - &(article.title);<? }
elseif ($topic) {
?>
VMUC - &(topic.name);<?
} else {
?>VMUC - <(title)><? }
?></title>
</simpara>
</programlisting>
<simpara>
Because elements are processed in the order they're listed it's
imperative they appear in the correct sequence within their parent
element. If the body element is listed before the head element within the
parent Root, the result is unpredictable.
</simpara>
<simpara>
Page elements take precedence over inherited page elements of the same
name, inherited page elements over style elements, style elements over
inherited style elements. Elements that are referenced but not present
are replaced with zero content so if a script references an article which
doesn't exist, the page is generated with no content.
</simpara>
<simpara>
We have at this point a fully decorated page with no actual content.
That's no good. There are two 'magic' element names, <[title]> and
<[content]> that will automatically be replaced with the title and
content of the current page, so if you store content there it will be
placed in the makeup built by the style.
</simpara>
<simpara>
Another way to insert content is to actively generate it. This is
most often, although by no means exclusively, used with
so-called 'active pages'. Active pages and static pages are both active
in the sense that they're PHP scripts, but while a static page will
only be activated for requests that target its URI directly, active
pages service anything that's targeted within their URI and beyond.
Everything beyond the page URI is split on the slashes and passed to the
script in the argv array, so if /article is an active page than the
script would be passed the array ('about', 'you', 'and', 'me') when
servicing /article/about/you/and/me.html.
</simpara>
<simpara>
The script can use this information to gather information from the
topic trees or even external data; everything the script in the
page content prints out will turn up where <[content]> was referenced.
</simpara>
<!--Site building End>
<!--Style Begin-->
<sect1>
<title>Building The Toplevel Style</title>
<simpara>
For the purpose of this tutorial, our next challange is building
a New Toplevel Style which is done within the Layout Administration
interface. In practice there is no rule for which of the four element
must be built and in what order they're built. You're able to choose
treat Content, Host, Layout and Group elements in any order that makes
sense to you. Individual elements like tables and headers which make
up the style building blocks for all Midgard web sites are treated
with the hierarchical structure of the Toplevel Style. In practice you
can build anyone of the four interfaces in any order.
</simpara>
<simpara>
Because vmucentertainment is a copy and redesign of VMUC we'll
copy and paste all the VMCU Style Elements into our new Toplevel style
which is named "vmucentertainment." The point is to preserve VMUC as a
reference. If we rename and edit the file beyound recognition, we
eliminate our reference.
</simpara>
<simpara>
Go to: Layout Administration -> Style Admin -> New
toplevel style
</simpara>
<simpara>
Fill in a name that describes your site,
possibly the domain name that you're creating a web site
for. Obviously in this case we're building vmucentertainment.
</simpara>
<programlisting>
Name: vmucentertainment.0.1
Inheritance: Should be set to "top level style."
</programlisting>
<simpara>
Owner is set to the group that is going to have password
authenticated access for administrating the web site. All
members of the specified group have read, write and delete
access which of course enables them to modify the style
elements.
</simpara>
<programlisting>
Owner: VMUC Admins
</programlisting>
<simpara>
After creating the toplevel style you can start populating
it with style elements e.g. HTML tables etc. When Midgard is
queried for a page, it looks for the element
<literal>ROOT</literal> which is in the toplevel style that
corresponds to the requested URL. The
<literal>ROOT</literal> element must exist in every Midgard
web site, as that is where page construction starts.
There are in fact 4 elements that will be searched
for for every request, in order of inclusion:
<literal>code-compat</literal>,
<literal>code-global</literal>,
<literal>code-init</literal>, and <literal>ROOT</literal>.
You can see them if you look at the file
<filename>midgard-root.php3</filename>.
</simpara>
<simpara>
Go to: Layout Administration -> Virtual Midgard Using
Company 0.1 -> New style element
</simpara>
<simpara>
Name the new element <literal>ROOT</literal>, then in the
Content text box enter the following HTML.
</simpara>
<programlisting>
<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<!--
<(version)>
-->
<html>
<(head)>
<(body)>
</html>
</programlisting>
<simpara>
We're introducing three concepts; page cards, delimiters and
elements. In this example the root document is a page card
that contains delimiters which point to head and body
elements. Delimiters are defined by placing an elements name
within the following tags <(element-name)>. Our head
and body elements cascade to their respective page cards
which contain elements and HTML tags that define the style
and contents of the head and body sections of our HTML
document. You're now realizing that Midgard generates pages
by cascading through page cards (and their
elements). Mark-up-code tags and the contents that exist
within the tags are interpreted during the cascading read
process and written to the page which is being dynamically
generated. This process continues until Midgard finishes
interpreting and reading the Content documents that populate
the requested page which of course exist between the opening
<html> and closing </html> tags.
</simpara>
<simpara>
When Midgard encounters elements that don't exist, it skips
the elements and continues to successfully build the page.
</simpara>
<simpara>
At this point we've built a <literal>ROOT</literal> page
card with delimiters that instruct Midgard to read the head
and body elements. Obviously, we need to build the head and
body elements. The process for building additional elements
is exactly the same as that used for building the
<literal>ROOT</literal> element. With an understanding of
the Layout Administration and Style Administration interface
you're ready to view the remaining VMUC style elements and
simply cut and paste them into your site.
</simpara>
</sect1>
<!--Style End-->
<!--Content Begin-->
<sect1>
<title>Content Management</title>
<simpara>
Within the Content Administration interface (Topic Admin) create a
"New toplevel topic:"
<itemizedlist>
<listitem>
Name: vmucentertainment
</listitem>
<listitem>
Owner: administrators
</listitem>
<listitem>
Description: This is the vmucentertainment site.
tutorial.
</listitem>
<listitem>
Note the topic id #
</listitem>
</itemizedlist>
<simpara>
Now we'll create "New article"s which act as sub-topics for the toplevel
topic "Midhoo." These subtopics are the portals to the categories of
links that you'll want for you site.
</simpara>
<simpara>
From Content Administration select Topic Admin "Midhoo" then select
"New article:"
</simpara>
<itemizedlist>
<listitem>
Title: Music
</listitem>
<listitem>
Name: Independent Record Labels
</listitem>
<listitem>
Author: Administrator
</listitem>
<listitem>
Start date: NA
</listitem>
<listitem>
End date: NA
</listitem>
<listitem>
Url http://www.mi-recordz.com
</listitem>
</itemizedlist>
<simpara>
Create several New articles by repeating these steps.
</simpara>
</sect1>
<sect1>
<title>Making the pages available.</title>
<simpara>
From the Host Administratin interface, select the "Root page" for
www.mi-recordz.com:8102 then select "New subpage:"
<itemizedlist>
<listitem>
Name: midhoo
</listitem>
<listitem>
Title: midhoo
</listitem>
<listitem>
Style: inherited
</listitem>
<listitem>
Type: active
</listitem>
<listitem>
Authentication: inherited
</listitem>
<listitem>
Author: Administrator, midgard
</listitem>
<listitem>
Content:
</listitem>
</itemizedlist>
<programlisting>
<?php
$topic = $context["topic"];
$x_in_a_row = 3;
if (!$topic) { ?> No such topic, sorry <?php }
else
{
echo "<font size=+1>" . $context["path"] . "</font><p>";
/* list subtopics */
$list = mgd_list_topics($topic->id);
echo "<table border=0>";
wh while ($list && $list->fetch())
{
?><tr><td align="left" valign="top"><a
href="&(list.id);.html"
>&(topic.name);</a></td><?php
for ($x=1; $x < $x_in_a_row; $x++)
{
?><td align="left" valign="top"><?php
if ($list->fetch()) { ?><a
href="&(list.id);.html"
>&(topic.name);</a><?php } else { echo " ";
}
echo "</td>";
}
echo "</tr>";
}
echo "</table>";
/* list articles */
echo "<hr><dl>";
$list = mgd_list_topic_articles($topic->id);
while ($list && $list->fetch())
{
?> <dt><a href="&(list.url);"
>&(list.title);</a><dd>&(list.content);
<?php
}
echo "</dl>";
}
?>
</programlisting>
* Submit: Submit the new subpage.
</simpara>
</sect1>
<sect1>
<title>You're now in the Host Administration, Midhoo Page Admin
interface where you'll build a new page element for the midhoo subpage.
</title>
<simpara>
Select "New page element:"
<itemizedlist>
<listitem>
Name: code-init
</listitem>
<listitem>
Type: ???
</listitem>
<listitem>
Content:
</listitem>
</itemizedlist>
<programlisting>
<?php
/* If no topic was specified, go to the root */
$context["root"] = $argv[0] ? $argv[0] : toplevel topic ID $t =
mgd_get_topic($context["root"]);
$context["topic"] = $t;
/* build path */
$ $path = $t->name;
$title = $t->name;
$t = mgd_get_topic($t->up);
while ($t)
{
$path = "<a href=\"" . $tmp->id
. ".html\">$t->name</a> > $path";
$title = "$t->name > $title";
$tmp = mgd_get_topic($t->up);
}
$context["path"] = $path;
$context["title"] = $title;
?>
</programlisting>
Substitute "ID" with the toplevel topic ID from....
</simpara>
</sect1>
<!--STYLE-->
</sect1>
<sect1>
<title>Advanced Features and Forthcoming Changes</title>
<simpara>
This section explores content handling scripts that are used within
the the core of the site. Additionaly, we'll add the Yahoo style
Internet portal named "Midhoo" which is written by Emile Heyns.
</simpara>
<simpara>
Midgard offers the possibility to separate content from layout
and user interaction. A great way to demonstrate this is the
yahoo-style directory site, where one group of people will
build the design and navigation of the site, while others
provide the articles.
</simpara>
<simpara>
The Content Management part concerns itself with the
management of, well, content. You can create trees of topics
which may in turn contain articles or other topic trees. Go
ahead and create a Toplevel topic in the Content Management
section. Give it the name 'Midhoo' and add a descriptive
text. You can leave the other fields empty at the
moment. After you press 'Submit' you'll see that an ID number
(topic #X) has appeared next to the name. Write this number
down; you'll want it later.
</simpara>
<simpara>
Under this Topic you can create new topics in the same way,
and under each topic you can create some articles. Fill in a
title and a name for each article, a description in the
content field, and the URL the content talks about in the URL
field. Make sure it's a full URL that starts with 'http://',
not just the site name.
</simpara>
<simpara>
All these articles are still not available to your public;
let's fix that. When you created your first pages you probably
wondered what the difference between an active or a static
page would be.
</simpara>
<simpara>
Static pages are used as-is; they are included in the style to
form a page to be presented to your visitors. Active pages do
mostly the same but add a little extra: everything in the URI
that follows will be presented to that page as a variable to
the script in the page. We'll use this feature now.
</simpara>
<!--Following refers to the Host Interface?-->
<simpara>
Create a new page under the root page of your test site, and
give it the name 'midhoo'. Make sure you mark it as active.
</simpara>
<simpara>
The page will contain a script that calls up the topics and
articles that we created earlier. This example assumes you
know a little about programming.
</simpara>
<simpara>
In the <literal>content</literal> part, enter the following
script:
</simpara>
<programlisting>
<?php
$topic = $context["topic"];
$x_in_a_row = 3;
if (!$topic) { ?> No such topic, sorry <?php }
else
{
echo "<font size=+1>" . $context["path"] . "</font><p>";
/* list subtopics */
$list = mgd_list_topics($topic->id);
echo "<table border=0>";
while ($list && $list->fetch())
{
?><tr><td align="left" valign="top"><a
href="&(list.id);.html"
>&(topic.name);</a></td><?php
for ($x=1; $x < $x_in_a_row; $x++)
{
?><td align="left" valign="top"><?php
if ($list->fetch()) { ?><a
href="&(list.id);.html"
>&(topic.name);</a><?php } else { echo "&nbsp;";
}
echo "</td>";
}
echo "</tr>";
}
echo "</table>";
/* list articles */
echo "<hr><dl>";
$list = mgd_list_topic_articles($topic->id);
while ($list && $list->fetch())
{
?> <dt><a href="&(list.url);"
>&(list.title);</a><dd>&(list.content);
<?php
}
echo "</dl>";
}
?>
</programlisting>
<simpara>
Remember the topic ID I asked you to note down? Create a new
page element for this page called <literal>code-init</literal>
and enter the following script, substituting the ID on the
second line.
</simpara>
<programlisting>
<?php
/* If no topic was specified, go to the root */
$context["root"] = $argv[0] ? $argv[0] : <userinput>toplevel topic ID</userinput>
$t = mgd_get_topic($context["root"]);
$context["topic"] = $t;
/* build path */
$path = $t->name;
$title = $t->name;
$t = mgd_get_topic($t->up);
while ($t)
{
$path = "<a href=\"" . $tmp->id
. ".html\">$t->name</a> > $path";
$title = "$t->name > $title";
$tmp = mgd_get_topic($t->up);
}
$context["path"] = $path;
$context["title"] = $title;
?>
</programlisting>
<simpara>
Now go back to the Layout Manager, select the Style you
created earlier, and select the <literal>ROOT</literal>
element. Click modify, and change the content to:
</simpara>
<programlisting>
<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<(comment)>
<head>
<title>
<?php echo $context["title"]; ?>
</title>
</head>
<body>
<h1><?php echo $context["title"]; ?></h1>
<(content)>
</body>
</html>
</programlisting>
<simpara>
Create a new element in this style, named
<literal>code-init</literal>, and enter the following
contents:
</simpara>
<programlisting>
<?php
$page = mgd_get_page($midgard->page);
$context["title"] = $page->title;
?>
</programlisting>
<simpara>
That's a lot of changes. We've introduced three new concepts
here: page elements, inline variable expansion, and Midgard
scripting.
</simpara>
<simpara>
In the <literal>ROOT</literal> style element we added a
reference to a style element called
<literal>code-init</literal>. We use this element to set up
some global data (the context if you will) for the page that's
being displayed.
</simpara>
<simpara>
The <literal>code-init</literal> and the
<literal>ROOT</literal> element which are defined within the
style do exactly what the previous <literal>ROOT</literal>
element did by itself: fetch the title and display it. This
just looks like more work.
</simpara>
<simpara>
So what does the page element do? Instead of just the plain
title of the page, which would be static, it assembles the
path you walked through your directory and puts that in a
variable which is used in the <literal>ROOT</literal> template
later. This way, the page can actively create a page title.
</simpara>
<simpara>
The style element also sets up some context for the current
page that will be displayed. We could have done this in the
page content, but we were gathering this information anyway so
this is more efficient.
</simpara>
<simpara>
The page content contains no text at all, just a script. This
script lists the directories under the currently selected
directory, and lists the articles it contains with hyper links
to the sites the articles reference.
</simpara>
<simpara>
The <literal><?php</literal> tag tells Midgard that a
script is starting, and the <literal>?></literal> tells
that the script ends -- temporarily. Anything not between
these tags will be sent to the browser as-is, and you can mix
scripts and HTML within a single page as much as you like, as
indeed we've done in this example.
</simpara>
<simpara>
If you look at this part of the script:
</simpara>
<programlisting>
while ($list && $list->fetch())
{
?> <dt<<a href="&(list.url);"
>&(list.title);</a><dd>&(list.content);
<?php
}
</programlisting>
<simpara>
You'll see I escape from my script temporarily to have this
piece of HTML sent to the browser for each time we pass
through the loop. But this HTML contains a little extra: the
<literal>&(...);</literal> construct will display a variable
from your script without having to use the script start and
stop tags.
</simpara>
<simpara>
<title>
Notes on style
</title>
Considerations for style include capitalization of proper nouns. Our
challenge is to develop a style that works on Monitors and in print
form. I think every proper noun should be treated exactly the same way.
Because we're dealing with monitors italicization doesn't work. This
Means capitalization of the first letter would be appropriate; however,
proper nouns in the Midgard Administration interface must also follow
the same exact style rule e.g. New toplevel style, from the administration
interface should be New Toplevel Style in all our documentation.
</simpara>
<simpara>
The administration interface uses mulitiple titles to describe the one
interface. We need to eliminate this because it's confusing. Is it the
Layout Administration or Style Administration interface? Because it's
one entity it can only have one name.
</simpara>
</sect1>
</article>
--
This is The Midgard Project's mailing list. For more information,
please visit the project's web site at http://www.midgard-project.org
To unsubscribe the list, send an empty email message to address
[EMAIL PROTECTED]