While I agree with Dave's assessment that JS and CSS files should be merged
and included only once, nevertheless I recognize there are times when
conditional inclusion of certain code in the header based on content lower
in the page is necessary. For example, you might want to add a link tag
pointing to an RSS feed that differs depending on the content requested. My
solution to this is a bit of a hack, but it works for me.
I use an application-specific key in Mason's "notes". At the top of the
autohandler, set it to an array, like so:
$m->notes('HTML_HEAD' => []);
This is available to all the components in your request. Any component that
wants to include a code snippet into the header pushes that snipped onto the
array.
push @{$m->notes('HTML_HEAD')}, $my_code_snippet;
Finally, in the autohandler <%filter> section, you shove that code into the
header using a regular expression replacement:
<%filter>
my $head = join "\n", @{$m->notes('HTML_HEAD')};
s{</head>}{$head</head>};
</%filter>
Of course there's a lot of room for refinements there, like removing
duplicates from the array, and the inherent fragility of the regexp, but in
most cases something like this works fine.
(Note, example code is off the top of my head, so don't necessarily copy and
paste. :)
Hope that helps.
----
Vince Veselosky
http://www.webquills.net
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Mason-users mailing list
Mason-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mason-users