From 9d284d46e7fbff1f649cedf44d9abf12c8496f60 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Fri, 6 Dec 2013 14:16:50 -0500 Subject: [PATCH] web staff : log templates (in progress) Signed-off-by: Bill Erickson --- web-staff-log.txt | 126 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) diff --git a/web-staff-log.txt b/web-staff-log.txt index e059fcdb62..49949d2a71 100644 --- a/web-staff-log.txt +++ b/web-staff-log.txt @@ -785,6 +785,132 @@ egNet.request(service, method, params).then( For the full technical rundown, see also http://docs.angularjs.org/api/ng.$q[Angular $q Docs]. +2013-12-06 Template Cornucopia +------------------------------ + +Using Angular on top of Template Toolkit gives us lots of options for +managing templates. TT lets us INCLUDE (etc.) shared templates on the +server. AngularJS lets us ng-include (etc.) both inline templates +(i.e. delivered within the main document) and lazy-loaded templates, +fetched as needed from the server. + +When to use each approach comes down to how each template is used in the +application. Is it needed on page load? Is it needed on every page? +Is it needed often, but not on page load? Is it needed rarely? You +have to weigh the cost of adding the template contents into the main +page body (does it add a lot of bytes?) to the cost of (potentially) +having to fetch it over the network as a separate document. + +Some examples: + +Classic TT Template +~~~~~~~~~~~~~~~~~~~ + +In the prototype, I'm loading the navigation template (t_navbar.tt2) +within the base document, i.e. the document used as the base template +for all top-level index files. + +[source,sh] +----------------------------------------------------------------------------- +[% INCLUDE "staff/t_navbar.tt2" %] +----------------------------------------------------------------------------- + +I'm doing this because the navbar is used on every page. It makes no +sense to load the template as a separate file from the server, because +that just increases the network overhead. + +Inline Angular Template +~~~~~~~~~~~~~~~~~~~~~~~ + +Modal dialogs in Angular have to be represented as separate, addressable +Angular templates. To give a chunk of HTML an "address", it can be +inserted into a +----------------------------------------------------------------------------- + +The modal dialog is then invoked like so: + +[source,js] +----------------------------------------------------------------------------- +// typically, templateURL refers to a (duh) URL, but inline +// templates can be loaded by ID. +$modal.open({templateUrl : 'uncat_alert_dialog', controller : [...]}); +----------------------------------------------------------------------------- + +**** +$modal is an angular-ui-bootstrap service. It's not part of core AngularJS. +**** + +Lazy-Loaded Angular Template +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +These behave much like inline templates, except the template file is +fetched from the server as needed. + +To change the inline template example above into a lazy-loaded template, +move the template to it's own web-accessible file: + +[source,html] +----------------------------------------------------------------------------- + + +----------------------------------------------------------------------------- + +Then load the file by URL instead of ID. + +[source,js] +----------------------------------------------------------------------------- +$modal.open({ + templateUrl : './circ/checkin/t_uncat_alert_dialog', + controller : [...] +}); +----------------------------------------------------------------------------- + +Templates All The Way Down +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Finally, here's an example where TT and Angular templates are used +together to deliver a modal dialog. + +staff/parts/alert_dialog.tt2 is a TT template for modeling a simple +alert dialog, whose text content is passed in by the containing template. +As before, to manage the dialog in Angular, it needs an address, so we +insert the contents of the TT template into an Angular template script. + +[source,html] +----------------------------------------------------------------------------- + +----------------------------------------------------------------------------- + +Note that this is kind of a contrived example. In the long run, +these types of reusable template chunks will likely live in Angular +directives, which allow you to embed templates in the JS and create new +HTML elements. (Imagine an directive). Once we resolve +the best i18n approach for such dynamic UI components (I have some +thoughts), this will probably be the better approach for these. +structure. + +Given a little time and experimentation, I believe we can find some +reasonable guidelines on how and when to use each approach. + Future Topics... ---------------- -- 2.11.0