[Date Index][Thread Index]
[Date Prev][Date Next][Thread Prev][Thread Next]

Re: WML for dummies (path evaluation order)

Hello Fritz Zaucker, in a previous mail you wrote:

> I am trying to put together a small set of WML-tags for Web-Page
> creation by some of our somewhat "computerly-challenged"
> colleagues. The idea is to have VERY simple input pages that are then
> translated according to some template page. 
> The one thing that I don't like to ask these people to do is to have
> to include as a (first line) something like
> #use WhatEverTemplate var1=value1 var2=value2
> (nor the #include equivalent).
> What I would prefer, instead, is a tag like
> <page-info author="XYZ" subject="XXX"  etc>
> and <page-info> would then decide what #include files to use.  The
> advantage would be that the users would only have to use one type of
> "mark-up", that is some tags.
> My understanding is that this would not work at the moment, as the
> #include commands are actually evaluated in path 1 whereas <page-info>
> would be evaluated later.


> Is there a solution/work-around?

Sure, for WML and Perl there is always a solution... ;-)

There are two ways here, I think: 

1. You can use "wml -i meta-template.wml ..." and then
   in meta-template.wml just define <page-info> in a way that it includes
   _all_ possible #include directives, every one surrounded with an <if...>.
   When you have not very much particular templates this can be an option,
   although I personally don't like it due to the include overkill.

2. You can use "wml -P prolog.pl ..." and then use a prolog.pl
   like the following:

    | #!/sw/bin/perl
    | #   read original page
    | $page = ''; $page .= $_ while (<STDIN>);
    | #   replace the header tags by the 
    | #   corresponding template usages
    | sub page_info {
    |     my ($argline) = @_;
    |     #   decide which templates to use
    |     #   and with what args based on the
    |     #   information we extracted out of
    |     #   the $argline...
    |     my $template = ...$argline...
    |     my $args     = ...$argline...
    |     return "#include \"$template\" $args\n";
    | }
    | $page =~ s|<page-info(.+)>|&page_info($1)|sge;
    | #   send filtered page
    | print $page;

    And then do whatever complicated calculation you want in the page_info()
    function based on $argline.  This is the typical WML way, I think. Because
    this is efficient and flexible.

                                       Ralf S. Engelschall
Website META Language (WML)                www.engelschall.com/sw/wml/
Official Support Mailing List                   sw-wml@engelschall.com
Automated List Manager                       majordomo@engelschall.com