Template Mode

Build Web Page Dialog - Template Mode



Complete web-site applications will typically generate customized web-content on the fly, using html templates created previously containing wild cards that are overwritten by the application at run time with real data. This can also be done to generate customized WordRad web pages, as already discussed in the section on The WordRad XML File Format. There was a lengthy discussion there on the structure of the WordRad XML file, indicating what sorts of changes can be made to it by a web-application.

However, the new Template Mode of the web page dialog allows you to enter wildcards directly into the dialog (e.g. for the names of images, etc.) This means that you can generate templates directly from WordRad now, and thus in many circumstances no longer have to modify an XML file directly in an editor. So if you initially select Template mode as shown above, WordRad will not modify or report errors about wildcard data you subsequently enter in the main Web Page dialogs. For example in the Web Images Dialog, we see that a wildcard has been entered for an embedded image name:

The double bracket string is common syntax in web application frameworks for expressing wildcards. (The rest of the string is a database item request.) The string above has no meaning to WordRad - only to a web application. WordRad will write that string directly to the xml file as specified above without complaint. It would also do the same for any garbage you entered above - and when opening an XML file with such a string - display it in the dialog without modification. Furthermore, there is no error reporting for any unfound items either. (Normal mode would report an error on the above when building the page and delete the entry from the XML file).

Template mode indicates to WordRad that the page being built has attributes that will not make sense outside the context of running web server application. Therefore, WordRad will not try to display such a page in the browser when you hit the View button in the Web Dialog. Instead, it merely displays the XML code:


Template Mode - More Features

Whenever you're generating multiple variants of a page for a production web application, regardless if these pages contain wildcards, you will find the Template Mode useful.

First of all, in Template mode, WordRad does not generate an html page to go along with the WordRad XML file, as it does in normal mode. The reason is that a template will not be running stand-alone anyway, and in all liklihood you will have already generated one parameterized html file that serves multiple WordRad XML files on your site. You will not want to clutter up your web-site directories with multiple boilerplate html files generated by WordRad that are not even being used. So WordRad doesn't generate them in template mode.

Another feature in Template Mode is that the Auxiliary Paths feature in the Web Page Dialog is activated:

This allows additional URL's to be appended to the front of font, texture, or image resource files if needed for the web-site server environment. Note that we happen to be using wildcards here as well: {{P}} resolves in this case to '/website_wr1/beers/wr_view1/' in the Django web app. You could of course have just entered that path directly in the above, as opposed to using a wildcard that only your web application understands. (Note: The first path above marked Main is just the output directory in the local file system for the generated web page and its resources. All other paths are URL's appended to resources.) Read the discussion on Auxilliary Paths for more details and also here.

Wildcards in WordRad

Most everything you specify in WordRad for your document, whether or not explicitly in template mode, will find its way into the generated XML file. This means that anywhere you can enter text in WordRad, you can potentially enter a wildcard that will be utilized by your web app. For example the following in the anchors dialog would work whether or not in template mode:

You can see that we've expressed a complex wildcard as the url for every single link. But WordRad would allow you to use any arbitrary string you wanted for a URL regardless if in template mode or not. So here we specify something that only our web-app will make sense of. The reason for an explicit template mode in the case of images, is that in normal mode they will be rejected if they can't be found (which would be the case with a wildcard) and also because image specs can be modified by WordRad when loading them from an XML file. Template Mode tells WordRad (among other things) "leave image filespecs alone."

Wildcards can even be used directly in the document window of WordRad:

"{{ drink.name }}" and "{{ drink.picture.credits }}" would be displayed as is in a stand-alone web-page, but if served from a web app, will be replaced by actual values retrieved from a database.

And finally, the web page title is a great place to put global directives to your web application. These would be template commands setting aspects of the application's configuration or mode, as opposed to generating visible text on the page. For example: Only the last item here, {{ drink.name }} corresponds to a visible element. {% load filters %} is a Django template directive to load the module called "filters". You could if necessary have a string of directives like that before the actual title. Often these types of directives are required to appear near the top of the file, which works out great as that's where the title tag is.

_____________________________________


The primary advantage of only generating templates directly through WordRad is that the resulting XML file will always be valid and accessible by WordRad. However, the mark-up and template languages employed by web-development frameworks can be quite flexible and complex, and there may be effects that can only be accomplished by modifying a WordRad XML file directly. In that case the existing documentation on The WordRad XML File Format and linked pages will be of value to know. The downside to modifying an XML file directly, is that it may result in a nonstandard WordRad file, or one that is not even valid XML (in which case WordRad won't open it at all). You should read the discussion on Opening Modified and Nonstandard WordRad XML files for more details.