Skip to content

Instantly share code, notes, and snippets.

@yoren
Forked from Shelob9/metaplate-from-file.php
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yoren/cffaa8fa2ac5cc06d79c to your computer and use it in GitHub Desktop.
Save yoren/cffaa8fa2ac5cc06d79c to your computer and use it in GitHub Desktop.
<?php
/**
* Load the template data from a file (file must be .html or .htm )
*/
//load from child theme or parent theme
$file = 'template.html';
echo caldera_metaplate_from_file( $file, $post_id );
//or use absolute patth
//$file = __FILE__ . '/template.html';
$file = dirname(__FILE__) . '/template.html';
echo caldera_metaplate_from_file( $file, $post_id );
//above examples willl pull meta fields by $post_id
//alternatively pass an array of data to use with third arg
$file = 'template.html';
$template_data = array(
'hats' => 'Many Hats',
'shoes' => 'No shoes',
'shirts' => array(
'blue',
'red'
)
);
echo caldera_metaplate_from_file( $file, null, $template_data );
<?php
/**
* Define a template in PHP and render with a Post's data.
*/
$metaplate[ 'html' ][ 'code' ] = 'Title: {{post_title}}<br />Shoes: {{shoes}}';
echo caldera_metaplate_render( $metaplate, 42 );
//note that the second argument ^^ is post ID, and is optional when global $post is set.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment