1. Zero to internet: your first website ↑

1.6. Review the merge template

Now let’s take a look at a couple of Notenik files that were invoked when you double-clicked on your build script.

These files can be opened using the same text editor you used to view the index.html file.

Let’s look first at the merge template file named chapter 01 - page template.html, which you will find within the factory/templates folder.

Here’s what you should see.

<?nextrec?>
<?output "../../web/=$title&f$=.html"?>
=$body$=
<?loop?>

Let’s take these lines one at a time.

<?nextrec?>

This is a Notenik Merge Template command that tells Notenik to repeat the following lines for each note found in the input. Right now we only have the Index page but, as we add other pages, they would take advantage of this same code.

<?output "../../web/=$title&f$=.html"?>

This line tells Notenik to open a new output file into which the following lines will be copied. Because this line follows the nextrec command, it will be repeated for each input note.

Following the name of the command we find the output path and filename for the file to be created. Each ../ takes Notenik up a level in the folder structure, starting from the location of the template file, until we get to the project folder itself, and then we direct the output into the web folder. What follows is the file name, which will be formed from the title field of the input note.

The &f is a Merge Variable Modifier telling Notenik to make all letters lowercase, and to replace spaces with dashes, to create a universally readable filename to be accessed from the web.

Then finally the .html specifies the file extension to be used for the output file.

=$body$=

This merge variable tells Notenik to place the entire body of the input note into the resulting web page.

<?loop?>

This command tells Notenik that it has reached the end of the lines to be repeated for each input note. So, in this case, the only contents of the output index.html file will be the body of the note.

So that’s it for the merge template, for now. Pretty simple, right?


Next: 1.7. Review the Script File