SiteTool v0.3.0 documentation
HowTo Guides¶
Contents
Turn a page into a template¶
Create a copy of index.html and name it something like tobetemplate.html
Create the Templates directory
Run this command:
due move -s ./ tobetemplate.html Templates/main.dwt
This will move the page to the Templates directory, update all the links it contains and leave the rest of the site alone. The -s option tells due ehere the site root is. You should now be able to view the main.dwt file in the browser and everything will still be correctly linked.
Next you need to add editable regions.
Add editable regions to a template¶
Editable regions in templates require markup like this:
<!-- TemplateBeginEditable name="breadcrumbs_bottom" -->
<!-- TemplateEndEditable -->
Any content which is between the two HTML comments is treated as editable and can be changed in the pages which use the template. In this case the editable region is named breadcrumbs_bottom.
Your template must have the following region which contains the <title> tag:
<!-- TemplateBeginEditable name="doctitle" --><title>James Gardner</title><!-- TemplateEndEditable -->
The template will usually also have editable regions named header, content, nav and footer but these are optional.
Tip
It is often a good idea to replace the existing content in the heading and content editable regions of the template with placeholder text such as HEADING GOES HERE and CONTENT GOES HERE so that you don’t have to delete lots of old content from the original page each time you create a new page from the template.
Apply a template to a page¶
Now that you have created a template you’ll want to apply it to a page.
First add this immediately after the first <html> tag right at the top of the page:
<!-- InstanceBegin template="Templates/main.dwt" codeOutsideHTMLIsLocked="false" -->
Replace Templates/main.dwt with the relative path from the page to the template.
Now, for each editable region in the template you’ll need to mark up the corresponding editable region in the page, but instead of using a pair of comments with the string TemplateBeginEditable and TemplateEndEditable in them, you use InstanceBeginEditable and InstanceEndEditable. Here’s the page markp for the title:
<!-- InstanceBeginEditable name="title" --><title>James Gardner</title><!-- InstanceEndEditable -->
The whitespace and line breaks should be unimportant.
Once you have updated the page you can reapply the template to correct any whitespace issues. Run this command:
due update -T -S index.html -s .
Create a new page using a template¶
Now that you have a template you can create a new page.
$ due create Templates/main.dwt faq/index.html
INFO: Saving file '/home/james/Desktop/spy/faq/index.html'...
INFO: Updating any context items...
Page created successfully.
The page faq/index.html gets created from the template but with all links and paths updated correctly.
Editing a page region¶
You can edit a page region with any editor but due also provides a set of command line tools to help. Here’s how to edit the content of the page you just created:
$ due set faq/index.html -ia content
The command loads whichever command line editor is specified in your EDITOR environment variable. When you save the temp file you are editing the content of the region you are editing within the page gets updated:
INFO: Updating file /home/james/Desktop/spy/faq/index.html...
INFO: Saving file '/home/james/Desktop/spy/faq/index.html'...
Successfully updated
I’ve written the command with the -i and -a options after the file itself because you generally update multiple regions for each page (heading, title, content etc) so having the region name at the end makes it a bit easier to edit the command for each region.
Deploy a site¶
Re-generate the sitemap:
due sitemap -c about.html sitemap.html
Create a list of all the orphaned files (which you don’t want on the server because they aren’t linked from anywhere so no-one can find them anyway):
due orphan -c about.html --relative > orps.txt
Then sync the site, excluding the orphaned files:
due deploy -c about.html --exclude-from orps.txt