Creating Ghost Partials Files

Partial files are a way for you to be able to keep your code clean and save you from having to edit the same code in multiple places. A good example for a partials file would be if you wanted to loop through all your posts and show their titles and an excerpt on the home page, as well as all the tag posts on a tag page. Then, say you want to show the date, rather than needing to open up both files and add the date code, you can just change the partials file and it will change in both places. Essentially a partials file is like a Javascript function that your calling from your main app.

Casper already has an example of a partials file, but if you are looking to create one, in the theme's root folder, create a partials folder if it doesn't already exist.

Then, inside this folder, create a new .hbs file called whatever you want (we will use example.hbs). Inside example.hbs, I am just going to create a super basic loop through each post:

Now, in my index.hbs and my tag.hbs, instead of having this same code loop through all of the posts, I am going to tell it to use the partial file. Add this line using the name of your partial file inside the quotes wherever you want that partials code to run:

And thats it! Now the code from the partial file will be inserted where you add that helper.