Scott Eade <[EMAIL PROTECTED]> writes: >On 8/03/2003 4:42 AM, "Henning P. Schmiedehausen" <[EMAIL PROTECTED]> wrote:
>> If you work along Hennings' two golden rules for templates, you should >> have not trouble whatsoever (and a much more robust and faster >> Template/Velocity service). :-) >Okay Henning, I'll bite: > What are your two golden rules for templates? See the comment at the head of TurbineVelocityTemplate.java * And now Hennings' two golden rules for using templates: * * Many examples and docs from older Turbine code show template pathes * with a slashes. Repeat after me: * * "TEMPLATE NAMES NEVER CONTAIN SLASHES!" * * Many examples and docs from older Turbine code show templates that * start with "/". This is not only a violation of the rule above but * actively breaks things like loading templates from a jar with the * velocity jar loader. Repeat after me: * * "TEMPLATE NAMES ARE NOT PATHES. THEY'RE NOT ABSOLUTE AND HAVE NO LEADING /". * It boils down to: If it is a file or something that should be referenced from a web page and is passed directly to the browser, separate it with "/". Like <img src="$content.getURI("/img/picture.jpg")"> This is passed on to the browser either as <img src="img/picture.jpg"> [1] or <img src="http://localhost/turbineapp/img/picture.jpg"> [1] If it is processed by the templating engine and passed on to the user through the turbine servlet, separate it with "," <a href="$link.setPage("user,addUser.vm")">Add new User</a> this is passed to the browser either as <a href="/turbineapp/app/page/user,addUser.vm">Add new User</a> [1] or <a href="http://localhost/turbineapp/app/page/user,addUser.vm">Add new user</a> [1] And if it is used to reference a java based element, like an action, use "." <form method="post" action="$link.setPage("user,addUser.vm").setAction("user.AddUserAction")> which translates to <form method="post" action="http://localhost/turbineapp/app/page/user,addUser.vm/action/user.addUserAction"> [1] The first reference in setPage is used to reference a page (probably a page to add an user) which therefore is separated with "," and the setAction() is used to select a java class which contains the actions for the form (somewhere along the module.path is a fully qualified java class, e.g de.intermeta.usermanager.modules.actions.user.AddUserAction which is used for this screen). My main problem with Template, Velocity and Pull Service is, that these three very different things have been vastly blurred and misunderstood and things like "TemplateLinkWithSlash" didn't really help newcomers to Turbine to understand the differences. While John did write in the head of this class * It is recommended that projects standardize on using the ',' * separator and use TemplateLink. But this class is available for * those who do not mind the inefficiency. it is still there, and I know that this is a big source of frustration. Same goes to the fact, that up to late in the 2.2 development cycle, most of the example TurbineResources.properties did contain things like services.VelocityService.default.layout.template= /Default.vm which is wrong. Templates are not pathes, there is notion of "relative" or "absolute". They don't contain slashes. And yes, we don't have good documentation for this which is the fault of all the Turbine developers. :-) Regards Henning [1] All examples considering that the servlet engine is running on localhost, port 80 using http, the application has been deployed as "turbineapp" and web.xml for this app contains <web-app> <servlet> <servlet-name>turbine</servlet-name> [...] <servlet-mapping> <servlet-name>turbine</servlet-name> <url-pattern>/app/*</url-pattern> </servlet-mapping> </web-app> -- Dipl.-Inf. (Univ.) Henning P. Schmiedehausen INTERMETA GmbH [EMAIL PROTECTED] +49 9131 50 654 0 http://www.intermeta.de/ Java, perl, Solaris, Linux, xSP Consulting, Web Services freelance consultant -- Jakarta Turbine Development -- hero for hire --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]