Pod Templates
(Since 1.2.0) -- add HTML formatting to raw Pod items
Templates are used to add mark-up (HTML, CSS, etc) to the raw Pod items. Column values are pulled into templates using Magic Tags. You aren't limited to Magic Tags though, you may also use HTML, CSS, JS, or PHP code to do whatever you'd like.
Example (List Template)
Example (Detail Template)
{@name}
Created on {@date}{@body}
Advanced Example (With PHP)
You can even show other Pod Templates within your Template, or do anything else you want to with PHP.{@name}
Created on {@date}{@body}
- {@name} Ideas <?php foreach($this->get_field('ideas') as $idea) { $idea = new Pod('idea',$idea['id']); // template might look like this: //
- {@name} echo $idea->showTemplate('idea_list'); } ?>
Displaying Templates
This code goes into either a Pod Page or a WP Template file (in the active theme folder).
<?php
$pods = new Pod('event');
$pods->findRecords('id DESC', 15);
echo $pods->showTemplate('event_list');
?>
The above example demonstrates how to call a List Template using showTemplate(). Below is an example of how to implement the Detail Template.
<?php
// Find the ID from the URL (it's usually the last segment)
$id = pods_url_variable('last');
// Pass the ID into the Pod class
$pods = new Pod('event', $id);
// Display the Detail Template
echo $pods->showTemplate('event_detail');
?>
You can also override the template code on a per-page basis:
<?php $override = ''; echo $pods->showTemplate('event_list', $override); ?>
Bypassing Templates
There might come a time when you want to skip using List or Detail templates altogether. This code would live on either a PodPage or a WP Template file.
<?php
// Bypass the List Template
$pods = new Pod('event');
$pods->findRecords('id DESC', 15);
while ($pods->fetchRecord())
{
// Display the "start_date" column
echo $pods->get_field('start_date');
}
?>
<?php
// Bypass the Detail Template
$pods = new Pod('event', $id);
// Display the "start_date" column
echo $pods->get_field('start_date');
?>
