Hiya
Personally, I think that using a plugin for this is probably over
complicating things.
I would just do this:
- in story.tt:
css_includes.story = 1
- in global_wrapper.tt:
FOREACH css = ['sports_wrapper','story','video_player'];
IF css_includes.$css;
'<link rel="stylesheet" type="text/css" href="';
css;
'.css" />';
END;
END;
However, if you're wanting to implement this to make the files smaller,
it's the wrong strategy. I try to put as much as possible into one file,
because for each stylesheet / javascript file that you link to, it means
an extra hit, which slows down your page rendering times.
Typically, I have one standard CSS file, and one for IE overrides (to
cope with IE bugs).
>From a current project, my main CSS is 1800 lines long, which seems
large, but with mod_deflate, that's only 7kB - the size of a small
image. And that gets cached.
Clint
> 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
>
>
_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates