(Also posted to comp.lang.perl.misc) Hi,
OK - scenario: I want .html files to be served as complete content, and .page files to be wrapped with the HTML head stuff, a menu and a footer. The idea is that most of my content will be .page files, wrapped with a constant set of stuff. But I can stick a .html file in and know that it will not be wrapped, should I need to... ie wibble.page is only the text content of a single page without any common stuff, tedious head/html tags and friends etc... I have a default handler with this in (gets called if the target URI cannot be resolved by apache): ==================== <%perl> # Handle permanant redirects $m->redirect('/venuespace.html', 301) if $r->uri() eq '/villagehall.html'; # OK - there is no target file for the URI my $rcompname = $r->uri(); # Try for a .page component $rcompname =~ s/\.html$/\.page/; if ($m->comp_exists($rcompname)) { $m->subexec($rcompname); return; } $m->abort(404); # Not found </%perl> <%attr> html_extra_headers => '<!-- Wibble -->' pagetitle => 'Robertsbridge' footercomment => '© 2010' navid => '' </%attr> ==================== So far, for a target exisiting .html, .cgi, .pl etc file, this does not get called. If the client asks for /index.html but index.page exists, this subexecs /index.page after checking for redirects, and if it fails, aborts with a 404. OK - now to handle the wrapping of index.page: We have an autohander thus =================== <%perl> # If the request is for a .page component, remapped by default.mas if ( $m->request_comp->name() =~ m/\.page$/ ) { $m->comp('/_mason/page.mas'); return; } # Otherwise, run with the original request else { $m->call_next; } </%perl> =================== Just for completeness, page.mas looks roughly like, with lots of snippage for brevity: =================== ... <html xmlns="http://www.w3.org/1999/xhtml"> ... <head> <title> <% $m->request_comp->attr('pagetitle') %> </title> ... <% $m->request_comp->attr('html_extra_headers') %> ... </head> ... <body id="<% $m->request_comp->attr('navid') %>"> ... <div id="headertext"> <h1><% $m->request_comp->attr('pagetitle') %></h1> </div> <!--headertext--> ... # Here we incorporate the index.page component: # <% $m->call_next %> <& /_mason/main_menu.mas &> ... <p id="footer-author"><% $m->request_comp->attr('footercomment') %></p> ... </body> </html> =================== Obviously there's loads of div blocks and other stuff in there, but you see the general execution flow... Does that look reasonably sane? If so, it means I "get" Mason. If not, well.. But I can say that it seems to function in reality. Thanks for any comments :) Cheers Tim -- Tim Watts ------------------------------------------------------------------------------ This SF.net email is sponsored by Sprint What will you do first with EVO, the first 4G phone? Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first _______________________________________________ Mason-users mailing list Mason-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mason-users