One of the first files you’re probably going to be making, is an index page file, while everyone’s index layout is going to be different, you’re basically going to want a welcoming heading, of course this is all up to you. But given the different templating engines, there are many ways that your index can look. Here’s how http://scripts.electrocode.net is templated; via slim, erubis(erb), and haml
That is basically what your files will look like; although the length and content of these indexes may vary, obviously.
There are other templating engines available to Sinatra, but for the purposes of this article, they are a moot point, due to a few things that can be done in those listed, but not in the others. Theres three main reasons I don’t list the rest.
- Not allowing Ruby code to be run inside them.
- The template is a block; rather than a file.
- They are used for other types of documents.
- Or they are used to generate other types of documents.
For example; Rabl is a templating engine, that allows Ruby code, and is a file based template, but is used for making XML and JSON API’s. The templating engines listed though allow nesting templates inside each other to form layouts, and that’s what we’ll be covering in the next page.