Someone recently mentioned adding css support - I've started down the road
to a half-baked support using the following mechanism (and in the next
couple of weeks I'm sure that I'll have it refined). Here's an example how I
use the same mechanism for javascript. I am already supporting inline CSS so
that I can entirely use 4.01/Strict. To support embedded CSS I plan to make
"config/stylesheet" sophisticated enough to do moderate optimisation to
aggregating duplicate properties and so on. Half-baked at the moment but
hopefully can illustrate some direction.

I've only been using TT2 for about 1-2 months now, so this probably
illustrates some of my naviety :-).

Matthew.

//--------------------------------------------------------------------------
------
// config/otherlink
//--------------------------------------------------------------------------
------

[%# ARGS
  #     link        # link URL
  #     text        # link text, defaults to link URL
-%]
[% IF link -%]
<a href="[% link %]" onclick="return window_open('[% link %]');">
[%-
        INCLUDE config/javascript
                name="window_open"
                code={
                        key => "function window_open(url)",
                        value =>
"window.open(url,'Window','width=640,height=480,scrollbars=yes,resizable=yes
'); return false;"
                };
-%]
[%- END -%]
[% text or link %]
[%- "</a>" IF link -%]

//--------------------------------------------------------------------------
------
// config/javascript
//--------------------------------------------------------------------------
------
[%-
IF name AND code;
        j_lookup = 0;
        FOREACH j = html.head.script.java;
                IF j_lookup == 0 AND j.name == name;
                        j_lookup = 1;
                END;
        END;
        IF j_lookup == 0;
                html.head.script.java.push({ name => name, code => code });
        END;
END;
-%]

//--------------------------------------------------------------------------
------
// usr/local/tt2/templates/html/head
//--------------------------------------------------------------------------
------
...
[% FOREACH i = html.head.script.java -%]
[% IF loop.first %]  <script type="text/javascript">
    <!--
[% END -%]
    [% i.code.key %] { [% i.code.value %] }
[% IF loop.last %]    -->
  </script>
[% END -%]
[% END -%]
...
[% FOREACH i = html.head.style.css -%]
[% IF loop.first %]  <style type="text/css">
    <!--
[% END -%]
    [% i.code.key %] { [% i.code.value %] }
[% IF loop.last %]    -->
  </style>
[% END -%]
[% END -%]
...
//--------------------------------------------------------------------------
------
// config/defaults
//--------------------------------------------------------------------------
------
        INCLUDE config/stylesheet
                name="body"
                code={
                        key => "body",
                        value =>
"font-family:Helvetica,Arial,Sans-Serif;color:#000000;background:#ffffff;"
                };


--
[EMAIL PROTECTED]



Reply via email to