About Smarty Templating

Smarty template engine for ProcessWire

Category 1Markup Generation
Markup modules that are called upon to generate or parse markup (like HTML). Markup modules are most often used on the front-end of a site (rather than admin).
Category 2Proof of Concept
Proof of concept modules are designed as examples or starting points for others to build from. May not be ideal for users wanting to plug-n-play.
Release StateBeta
Close to stable, but users are advised to be cautious and test thoroughly.*
Authorniutech
Module Version1.0
Class NameSmartyTemplating
Compatibility2.2, 2.3, 2.4
Date AddedFebruary 9, 2013
Last UpdatedFebruary 8, 2013
Recommended ByNew recommendations may take up to 1 day to appear.

Details

This module allows you to use Smarty 3 template engine in ProcessWire CMS. It provides not only nifty template tags and functions, but also it caches whole templates.

Instructions

Copy the folders to your /site folder, enable the module and set caching lifetime in the options. Now edit the default template in your /site/template folder or make one from scratch. Remember: despite the default *.php extension, Smarty templates don't eval PHP. Instead, use only Smarty tags:

Code:
{$page->title}{$page->body|truncate:50} {$home=$pages->get("/")} {foreach $home->children as $child} {$child->title|escape} {if $child->field}has this field!{/if} {/foreach} {* this is a comment *} {include './head.inc'} {function divclass} <div class="{$c}">{$b}</div> {/function} {divclass c="myclass" b=$page->body} {html_select_date start_year="-1" end_year="+1"} {extends file="home.php"} {block "sidebar"}Replacement sidebar{/block}

README

{:"aria-hidden"=>"true", :class=>"octicon octicon-link"}Smarty Templating for ProcessWire

This module allows you to use Smarty 3 template engine in ProcessWire CMS.

{:"aria-hidden"=>"true", :class=>"octicon octicon-link"}Installation

Just copy both /site/modules and /site/templates folders to your /site folder. Then go to the admin panel and enable this module. In the options you can enable Smarty caching and change the cache lifetime. Upon saving, three folders should be created in your /site/assets/cache: SmartyCache, SmartyConfigs and SmartyTemplates_c. Otherwise create them and chmod them to 777.

{:"aria-hidden"=>"true", :class=>"octicon octicon-link"}Quick tutorial

Do not use <?php ?> tags in your templates! (despite the default *.php template extension).Instead use { } tags accordingly:

Smarty:                              PHP:
{$page->title}                       <?php echo $page->title; ?>
{$home=$pages->get("/")}             <?php $home=$pages->get("/"); ?>
{foreach $home->children as $child}  <?php foreach($home->children as $child): ?>
    <li>{$child->title}                  <li><?php echo $child->title; ?>
    {if $child->field}!!!{/if}</li>      <?php if($child->field): ?>!!!<?php endif; ?></li>
{/foreach}                           <?php endforeach; ?>
{* this is a comment *}              <?php /* this is a comment */ ?>
{include './head.inc'}               <?php include './head.inc'; ?>

{:"aria-hidden"=>"true", :class=>"octicon octicon-link"}Author

Jerzy Głowacki

Comments

No comments yet. Be the first to post!

Post a Comment

Your e-mail is kept confidential and not included with your comment. Website is optional.