与模板实现相关的 Catalyst Web 应用程序设计问题
我刚刚开始使用 Catalyst,并且仍在努力了解它,所以请耐心等待。
我必须生成一个表格(HTML),其中包含指向特定数据库记录的链接。这些记录跨越许多数据库表。该表 (HTML) 的行为应类似于已定义的包装模板中的菜单。单击此“菜单表”的元素应加载带有“菜单表”的页面以及其下方选定的记录内容(用于查看或作为编辑表单)。
我的想法是使用链式操作/方法来生成内容(足够简单)。然后使用单个模板(模板工具包)来确定我们是否仅显示“菜单表”,或者“菜单表”和所选记录的视图,或者“菜单表”和用于编辑所选记录的表单。例如,模板总是会生成“菜单表”,但根据 FormFu 操作/方法是否使用它,它可能会也可能不会生成用于编辑所选记录的表单。因此,模板将具有用于显示或编辑记录的条件代码。
感觉就像需要模板类型解决方案中的模板一样。有 Catalyst 经验的人可以透露一些信息吗?也许评论一下我是否朝着正确的方向前进?
提前致谢。
I'm just starting out with Catalyst and am still trying to wrap my head around it, so please bear with me.
I have to generate a table (HTML) of what amounts to links to specific database records. The records span many database tables. This table (HTML) should behave like a menu within the already defined wrapper template. Clicking an element of this 'menu table' should load a page with the 'menu table' as well as the selected record contents below it (either for viewing or as a form for editing).
My thought is to use chained actions/methods to produce the content (straight forward enough). Then use a single template (template toolkit) to determine if we display only the 'menu table, or the 'menu table' and a view of the selected record, or the 'menu table' and a form to edit the selected record. So for example, the template would always produce the 'menu table', but depending on if it is being used by a FormFu action/method, it may or may not produce the form for editing the selected record. So the template would have conditional code for displaying or editing records.
It almost feels like a template within a template type solution is required. Can someone with Catalyst experience shed some light? Maybe comment on whether or not I'm headed in the right direction?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您知道进行服务器调用时(而不是在客户端)对象的状态,那么您应该能够使用模板工具包中提供的标准 IF 和 BLOCK 语句内容来解决此问题。 BLOCK 将为您提供模板内的模板(带变量),并且 IF-ELSE-END 也可用。请参阅此处的文档:
http://template-toolkit.org/docs/manual/Directives .html
但是,如果您只知道客户端,那么注释中的 Mugen 是正确的,如果我在很短的时间内编写类似的代码,我会编写 ajax 页面,然后我会使用 jQuery 克隆来对抗当然,在进行ajax调用之后,模板div来填充数据并相对快速地构建菜单:
http:// /api.jquery.com/clone/
http://api.jquery.com/jQuery .ajax/
但我无法确定给出的规格,并且没有一些代码可供查看。
If you know the state of the objects when the server call is made (rather than on the client side), then you should be able to resolve this issue using the standard IF and BLOCK statement stuff available in template toolkit. BLOCK will give you the template within a template (with variables) and IF-ELSE-END is also available. Please see the documentation here:
http://template-toolkit.org/docs/manual/Directives.html
However, if you only know client side, then Mugen in the comments is correct, if I were coding something like this on a short timeline, I would write the ajax page, then I would use jQuery clone against a template div to fill in the data and build the menus relatively quickly, after making the ajax call, of course:
http://api.jquery.com/clone/
http://api.jquery.com/jQuery.ajax/
But I can't be certain with the specs given, and without some code to look at.
正如荷鲁斯评论的那样,给您这个问题的最佳答案在一定程度上取决于服务器端是否知道相关对象的状态(查看或编辑)。
不要忘记,TT 为您提供了在现有模板中
INCLUDE
或PROCESS
另一个模板的能力。因此,假设服务器端(以及 TT)知道对象的状态,类似这样的事情应该非常简单:您可以使用这种方法使事情保持相当干燥。
As Horus commented, giving you the best answer to this question depends a bit on whether the server side knows the state (view or edit) of the object in question.
Don't forget that TT offers you the ability to
INCLUDE
orPROCESS
another template within an existing one. So assuming the server-side (and hence TT) knows the state of the object, something like this should be pretty straightforward:You can keep things pretty DRY with that approach.