Hi

I've been working on a Template toolkit plugin that will make it easier for
our client side developers to include relevant CSS files in their templates.
The basic idea is that developers can use the plugin as follows:

[% USE CSS href="video_player_styles.tt" media="screen" %]
[% USE CSS href="story_styles.tt" media="screen" %]

It's a singleton plugin, and basically maintains a list of the CSS files
that have been used so far, in the order that they were used. This means
that in our global wrapper template we can use the plugin to output an
ordered and de-duplicated set of HTML link tags to include all the CSS.

[% USE CSS %]
[% CSS.as_html %]

I'm also planning a similar plugin for including JavaScript files. The plan
is that each template will know which non TT files it is dependent on.

The plugin works exactly how I want it to most of the time. However, there
is one problem. In some situations we are using more than one wrapper
template.There might be a global site wrapper and then a section specific
wrapper.

For example, we might be processing a template story.tt which includes
another template called video.tt, and has the wrappers sports_wrapper.tt and
global_wrapper.tt. In this case the templates would be processed in this
order:

story.tt -> video_player.tt -> sports_wrapper.tt -> global_wrapper.tt

If story, video_player and sports_wrapper all use the CSS plugin to include
stylesheets of the same name, then [% CSS.as_html %] will output the
following:

<link rel="stylesheet" type="text/css" href="story.css" />
<link rel="stylesheet" type="text/css" href="video_player.css" />
<link rel="stylesheet" type="text/css" href="sports_wrapper.css" />

However the desirable output for our developers would be:

<link rel="stylesheet" type="text/css" href="sports_wrapper.css" />
<link rel="stylesheet" type="text/css" href="story.css" />
<link rel="stylesheet" type="text/css" href="video_player.css" />

This is because the order that the templates are 'displayed' in (as far as a
developer is concerned) is:

sports_wrapper.tt -> story.tt -> video_player.tt

Is there any easy way, in my plugin, to establish how the templates are
displayed? I.e some kind of list going from outermost to innermost
(sports_wrapper.tt, story.tt, video_player.tt).

Alternatively, is there anyway for the plugin to detect whether the template
it was called from is a wrapper? Something like
$context->stash->{'component'}->is_a_wrapper would be ideal.

Is the only solution not to use more than one wrapper?

Thanks in advance for any help

Rob

Reply via email to