--- title: Panini description: A flat file compiler that powers our prototyping template. Create pages with consistent layouts and reusable partials with ease. video: 't_ekdBMj4cc' library: github: https://github.com/zurb/panini docs: https://github.com/zurb/panini --- {{{{raw}}}} If you've ever created a static site, maybe you had five pages that all shared the same header and footer. You create your first page, and then copy and paste the common elements to the next page. But now if you need to make a change to the header, the change has to be made across multiple files. Panini is a flat file compiler that uses the concepts of templates, pages, and partials—powered by the [Handlebars](http://handlebarsjs.com/) templating language—to streamline the process of creating static prototypes. Our [prototyping template](starter-projects.html) uses Panini, along with a host of other tools for processing Sass, JavaScript, and images, to make creating static prototypes easy. It's already been configured to utilize all of the features below, but if you want to learn the specifics of how to configure the library, head over to the [Panini GitHub page](https://github.com/zurb/panini). --- ## Basics: Templates & Pages A **template** is a common layout that every page in your design shares. It's possible to have multiple templates, but generally you'll only need one, and a page can only use one template. In the prototyping template, the default layout is found under `src/layouts/default.html`. Here's what a basic template might look like: ```handlebars
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Praesentium ducimus eligendi, reiciendis corporis quam facere quaerat qui, aspernatur molestiae velit, vero ea quisquam laborum corrupti repudiandae totam, at aliquam esse.
``` Note that there's no `` or `` tags, and no header or footer. This code will be injected into the `{{> body}}` declaration when Panini assembles your pages. In the prototyping template, these finished files are compiled into a standalone folder called `dist` (short for "distribution"), which also includes your processed CSS, JavaScript, and images. This folder can easily be uploaded to any web server, or Notable's [Hosted Prototypes](http://zurb.com/notable/features/hosted) service. --- ## Partials Partials are a feature of Handlebars which allow you to inject HTML anywhere in a page or layout. They're really useful when you need to repeat certain chunks of code throughout your pages, or to keep individual files from getting too cluttered with HTML. Here's an example of a layout file that divides its key sections into partials: ```handlebarsYou are here: {{page}}
``` ### root Use `{{root}}` before a file path to make sure it works no matter what folder the current page is in. For example, a path to an external CSS file will need to be different if the current page is at the root level of your site, or in a sub-folder. Here's how you'd use it with a `` tag: ```handlebars ``` If the page is `index.html`, the path will look like this: ```html ``` If the page is `folder/page.html`, the path will look like this: ```html ``` The `../` is added only on pages in a sub-folder, so the CSS can still be properly loaded. --- ## Helpers Helpers are special functions that manipulate content on the page. In addition to [Handlebars's built-in helpers](http://handlebarsjs.com/builtin_helpers.html), Panini includes a few custom helpers and you can add your own. ### ifequal Displays the HTML inside the helper if the two values are equal. ```handlebars {{#ifequal foo bar}}foo and bar are equal
{{else}}foo and bar are not equal}} {{/ifequal}} ``` ### ifpage Displays the HTML inside the helper only on specific pages. In the below example, the HTML inside the helper will only show up on the `index.html` page. ```handlebars {{#ifpage 'index'}}
This is definitely the Index page.
{{/ifpage}} ``` You can also check for multiple pages. If *any* name in the list matches the current page, the HTML will appear. ```handlebars {{#ifpage 'index' 'about'}}This is definitely either the Index or About page.
{{/ifpage}} ``` ### unlesspage The opposite of `#ifpage`, `#unlesspage` will only display the HTML inside of it if the current page is *not* in the parameters. ```handlebars {{#unlesspage 'index'}}This is definitely not the Index page.
{{/unlesspage}} ``` ### repeat Repeats the content inside of it `n` number of times. Use this to easily print lots of duplicate HTML in a prototype. ```handlebars