<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-GB link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Thanks for your feedback Denny, Ben and Stuart &#8211; good food for thought!<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>I think some sort of handling logic in Root&#8217;s default action to test for the existence of template and error or 404 if it doesn&#8217;t &#8211; is the way forward.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Many thanks,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Anthony<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><div style='border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt'><div><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm'><p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span lang=EN-US style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> Stuart Watt [mailto:swatt@infobal.com] <br><b>Sent:</b> 11 October 2010 19:35<br><b>To:</b> The elegant MVC web framework<br><b>Subject:</b> Re: [Catalyst] Displaying template files without adding new controller actions<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p>&nbsp;</o:p></p><div><p class=MsoNormal>If it's a TT file you need (i.e., not static), along with appropriate processing, you can make a variation on Ben's suggestion by using the $c-&gt;request-&gt;arguments, and putting the file name into&nbsp;$c-&gt;stash-&gt;{template} before handing off to the TT view, which is likely to be the default. This is a slight variation on ben's suggestion, which will only hit the file system when looking at the right part of the URI space.&nbsp;<o:p></o:p></p></div><div><p class=MsoNormal><o:p>&nbsp;</o:p></p></div><div><p class=MsoNormal>I've not tested this, but it'd just look something like:<o:p></o:p></p></div><div><p class=MsoNormal><o:p>&nbsp;</o:p></p></div><div><p class=MsoNormal>sub dynamic : Local {<o:p></o:p></p></div><div><p class=MsoNormal>&nbsp;&nbsp;my ($self, $c) = @_;<o:p></o:p></p></div><div><p class=MsoNormal>&nbsp;&nbsp;my $args =&nbsp;$c-&gt;request-&gt;arguments();<o:p></o:p></p></div><div><p class=MsoNormal>&nbsp;&nbsp;$c-&gt;stash-&gt;{template} = join('/', @$args);<o:p></o:p></p></div><div><p class=MsoNormal>};<o:p></o:p></p></div><div><p class=MsoNormal><o:p>&nbsp;</o:p></p></div><div><p class=MsoNormal>This omits the error handling (assumes TT will take care of that) but should only handle requests that begin /dynamic. The arguments() method returns additional stuff after &quot;/dynamic&quot; in the requesting URL.&nbsp;<o:p></o:p></p></div><div><p class=MsoNormal><o:p>&nbsp;</o:p></p></div><div><p class=MsoNormal>I do something similar in my code (it's not precisely the same, as I retrieve the file contents through a model) and it works pretty well for us.&nbsp;<o:p></o:p></p></div><div><p class=MsoNormal><o:p>&nbsp;</o:p></p></div><div><p class=MsoNormal>For security, you probably want to remove stuff like &quot;..&quot;, just to be safe.&nbsp;<o:p></o:p></p></div><div><p class=MsoNormal><o:p>&nbsp;</o:p></p></div><div><p class=MsoNormal>All the best<o:p></o:p></p></div><div><p class=MsoNormal>Stuart<o:p></o:p></p></div><div><p class=MsoNormal><o:p>&nbsp;</o:p></p></div><p class=MsoNormal><o:p>&nbsp;</o:p></p><div><div><p class=MsoNormal>On 2010-10-11, at 11:14 AM, Ben van Staveren wrote:<o:p></o:p></p></div><p class=MsoNormal><br><br><o:p></o:p></p><div><p class=MsoNormal>The other way to do it (and this is hackish), would be something like this:<br><br>...<o:p></o:p></p></div><p class=MsoNormal><br><br><o:p></o:p></p><div><p class=MsoNormal>This is, however, very non-optimal since you are hitting the filesystem for every request that wasn't satisfied by an existing action. Like I said, you can either let the webserver serve up static pages. If you are worried about how the URL looks in the browser, some mod_rewrite magic will fix that for you, but that's a subject for another list :)<br><br>...<br><br>Anthony Gladdish wrote:<br><br><o:p></o:p></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><p class=MsoNormal>I want to add quite a few .tt2 pages to the app, in various directories.<o:p></o:p></p></blockquote><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><p class=MsoNormal>I don't want to have to create a Controller action per added template page ( this is the only way I know of adding a web page to a Catalyst app ).<o:p></o:p></p></blockquote><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><p class=MsoNormal>Every time I add a new page I'll have to add a new action to represent that page then restart the server. There must be a way to add as many template pages as required, and have a single Controller action display the web page if it's corresponding template exists, otherwise 404.<o:p></o:p></p></blockquote><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><p class=MsoNormal><o:p>&nbsp;</o:p></p></blockquote><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><p class=MsoNormal>...<o:p></o:p></p></blockquote><p class=MsoNormal><br>-- <br>Ben van Staveren<br>phone: +62 81 70777529<br>email: <a href="mailto:benvanstaveren@gmail.com">benvanstaveren@gmail.com</a><o:p></o:p></p></div></div><p class=MsoNormal><o:p>&nbsp;</o:p></p></div></div></body></html>