This tutorial was contributed to our Github wiki by user bonsak. How to make a Pods List Page using Pods Pages and Pods Templates: For this example – BUNNIES! We have already created the Bunnies Pod as seen in Part 1. If you have not done this step, please make sure to have all of your pods data set up and ready. This pod “Bunnies” contains one of every field type for example purposes. For the list page, we first need to go to the “pages” tab and click “add new page”. This page will be called “bunnies” because it will be a list of all of the bunnies in our pod. Inside of that page we will enter the page title and leave the page template at default. Here we have the code that will go in our page.
Breaking down the code we have the heading of the page first. This is optional, and any other HTML tags and content can be added here as well. We then register the pod that we want to call using new Pod (‘bunnies’); The next line of code is to get all records inside of the bunnies pod using findRecords() and sorting by the name field. Descriptions of why we use t.name over name is found in the findRecords page. Finally, we are going to display the pods, but instead of adding in all of the layout information here, we will use a pods template called ‘bunnies_list’. Now we will go over to the “templates” tab and click “Add new template” and name it exactly the same thing you referenced in the previous pods page, in this case it is ‘bunnies_list’. Inside of our template we will build the structure to display out pod items on the front end of the website. In our bunny list, we want a grid with the photo and name of the bunny and a link to the bunny’s detail page.
Breaking down the code, we see a very basic, easy to understand HTML structure – nothing new there. The new stuff is in the magictags! Pods Framework comes with a number of built in magic tags such as the detail_url and creates magictags for each of your fields such as the name and photo field. There is an added bonus to file upload fields where you can use yourfieldname.guid to just get the file’s location url. Save this template, and view your page, and bask in it’s glory… Until you click the name and see that you have one more step if you want a detail page for each pod item.