Reputation: 193
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.
Upvotes: 0
Views: 310
Reputation: 9188
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
or PROCESS
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:
WRAPPER "wrapper.tt";
PROCESS "menu.tt" IF is_menu;
SET tmpl = is_edit ? "edit" : "view";
PROCESS "$tmpl.tt";
You can keep things pretty DRY with that approach.
Upvotes: 1
Reputation: 1175
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/jQuery.ajax/
But I can't be certain with the specs given, and without some code to look at.
Upvotes: 1