Template Files

Guide to writing template files

Remember that for each page tracked by Nift there is a specified template path. When building a page, Nift will start processing the template file the same as it will process any other file. Consequently everything that applied to writing content files also applies to writing template files. However, unlike content files, template files need to specify where content and (optionally) the page title are to be inputted.

Specifying where content is to be inputted

Nift treats any instance of @inputcontent as being equivalent to @input(path-to-content), where path-to-content is the content path for a page.

Note: if @inputcontent is in any dependency of a page's content file (content file inclusive), then an input loop would be formed when attempting to build the page so Nift will (at least it should) throw an error. You may however put @inputcontent in any other dependencies of the template file. For example were your template to include a file template/body.template, it is fine for @inputcontent to reside in body.template and not the main template file.

Specifying where the page title is to be inputted

When building a page, Nift will replace any instance of @pagetitle with the title Nift has tracked for the page. Unlike @inputcontent, @pagetitle may be placed inside content files (template files inclusive).

Example template files

A very simple template file, that specifies both where content and the page title are to be inputted, would be:

		    						<!DOCTYPE html>
		    						<html>
		    							<head>
		    								<title>site title - @pagetitle</title>
		    							</head>
		    
		    							<body>
		    								@inputcontent	
		    							</body>
		    						</html>
		    					

It can be convenient to break what would typically be found inside the template file up into various content files. For example you may have template/head.content, template/menu.content and template/footer.content. A suitable template file, say the default template/page.template would then be:

		    						<!DOCTYPE html>
		    						<html>
		    							<head>
		    								@input(template/head.content)
		    							</head>
		    
		    							<body>
		    								@input(template/menu.content)
		    
		    								@inputcontent	
		    
		    								@input(template/footer.content)
		    							</body>
		    						</html>
		    					

Note: the head tags may be put inside either template/page.template or template/head.content. However if the head tags are left inside template/page.template then, rather than specifically having to alter template/head.content, the head may be altered from both template/page.template and template/head.content.