I'm creating a plugin that is directly correlated with a theme I'm developing wich is using Timber. My plugin could render some built in templates (when I call a shortcode the plugin reply with the correct teplate); Those templates are, for now, PHP files. I would use Timber to render those files.
Unfortunatly Issue #261 is still open. And I have no idea on how I can obtain the expected behaviour on the current timber codebase.
Expected behaviour:
- Register my plugin path for views after the theme path.
- When a view is called, Timber first check on theme directory, than on the plugin one.
How can I obtain this? Right now I have tested with the templates on my theme and I simply call Timber.render(); but I don't have the local path included.
Standard PHP plugin code:
// On plugin load
add_shortcode('render_social_icons', array($this, 'render_social_icons'));
public function render_social_icons($atts, $content)
{
$atts = shortcode_atts(array(
'class' => '',
'el-class' => '',
'link-class' => '',
'icon-class' => '',
'size' => '',
), $atts);
ob_start();
?>
<ul class="social-icons shortcode <?php echo $atts['class']; ?>">
<?php
$socials = my_socials_links();
foreach ($socials as $social) :?>
<?php
$id = $social['id'];
$title = $social['name'];
$baseurl = $social['baseurl'];
$icon = $social['icon'];
$social_data = get_theme_mod($id);
if (!empty($social_data)) :?>
<li class="<?php echo $id; ?> <?php echo $atts['el-class']; ?>">
<a target="_blank" title="<?php echo $title; ?>" href="<?php printf($baseurl, $social_data); ?>"
class="<?php echo $atts['link-class']; ?>">
<i class="<?php echo $icon; ?> <?php echo $atts['icon-class']; ?> <?php echo $atts['size']; ?>"></i>
</a>
</li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
<?php
return ob_get_clean();
}
Converted function for Timber (still a plugin file):
// On plugin load
add_shortcode('render_social_icons', array($this, 'render_social_icons'));
public function render_social_icons($atts, $content)
{
$atts = shortcode_atts(array(
'class' => '',
'el-class' => '',
'link-class' => '',
'icon-class' => '',
'size' => '',
), $atts);
return Timber.compile('shortcodes/social.twig', array(atts, my_socials_links());
}
The shortcodes/social.twig is inside the current theme folder, I would like to load this twig template file from the plugin foder.