Jump to content

Popcorn - the flexible, fast, and simple template engine for PHP!


Awilum

Recommended Posts

popcorn_promo.png

 

Hello ) I wrote this simple template engine for PHP! Popcorn!

 

Site: http://popcorn.template-cms.org/

 

Built-in popcorn template codes

{echo $var} - Output variable

{var name $var2} - Assign local template variable

{const name $value} - Assign constant

{file 'filename'} - Load file

{run function()} - Run php function

{if expr} {else} {elseif expr} {/if}- If construct

{loop $mas as $item}{/loop}

{loop $mas as $key => $item}{/loop} - Loop construct

{codes} - Show all declared template codes

{vars} - Show all declared variables

{dump $var} - Dumps information about a variable

{assign var 'value'} or {assign var $value} - Assign global variable

{include 'template_name'} - Include other template

 

 

Simple php application

<?php

    // Include Popcorn
    include 'popcorn/popcorn.class.php';

    // Initialize a Popcorn object	
    $popcorn = new Popcorn();

    // Variable assign
    $variable = 'Hello World!';
    $popcorn->assign('variable',$variable);
    $popcorn->assign('show',true);

    // Draw the template	
    $popcorn->draw('page');	

?>

 

 

 

Simple template

<html>
<head>
    <title>Simple template</title>
</head>
<body>
    {if $show}	
        {echo $variable}
    {/if}
</body>
</html>

 

 

p.s.

TCodes - closed!

 

Link to comment
Share on other sites

Show all variables? Declare global variables? Include a file? Assign constants? That's not a template engine, but a programming language. Many of PHP's typical syntax is still visible. It should make designers easier to write/make templates.

 

PHPTal really hits the nail on the head by allowing you to write simple XHTML to create your templates.

Link to comment
Share on other sites

ignace

http://www.smarty.net/docsv2/en/ - No creating variables in template or including ?

 

I never said Smarty is a good templating engine. A template engine is to assist designers in creating the templates without having to learn PHP or anything complex, and PHPTal succeeds in this by using default XHTML syntax. If your template engine imitates basic PHP syntax then you could as well be writing PHP which in itself can be considered a template engine.

Link to comment
Share on other sites

ignace

>A template engine is to assist designers in creating the templates without having to learn PHP or anything complex

hm... I think php programmer will learn Popcorn faster than Smarty. Because syntax like in php and smarty. Yes. php programmers also use template engines.

 

php - TEMPLATE ENGINE

---------------------------------------

 

<ul>
<?php if(isset($languages) && is_array($languages) && sizeof($languages)) foreach($languages as $language) { ?>
      <li><?php echo $language; ?></li>
<?php } ?>
</ul>

 

 

Smarty

---------------------------------------

 

<ul>
{foreach from=$languages item=language}
    <li>{$language}</li>
{/foreach}
</ul>

 

 

Popcorn

---------------------------------------

 

<ul>
{loop $languages as $language}
     <li>{echo $language}</li>
{/loop}
</ul>

 

 

 

I do not see any problems for designers)

 

 

Link to comment
Share on other sites

I just looked at a simple example phptal  and does not understand anything Оо

<div class="item" tal:repeat="item itemsArray">
    <span tal:condition="item/hasDate" tal:replace="item/getDate"/>
    <a href="${item/getUrl}" tal:content="item/getTitle"/>
  <p tal:content="value/getContent"/>
</div>

 

Link to comment
Share on other sites

Snippets for  Sublime Text

 

@@ - {@ $var}

@echo - {echo $var}

@if - {if $var} {/if}

@ifelse - {if $var} {else} {/if}

@ifelseif - {if $var} {elseif $var} {/if}

@loop - {loop $key as $item} {/loop}

@var - {var name $var2}

@const - {const name $value}

@assign - {assign var $value}

@include - {include 'template_name'}

@file - {file 'filename'}

@run - {run function()}

@vars - {vars}

@codes - {codes}

@dump - {dump $var}

 

Download: popcorn.zip

 

Install: Unpack the archive to a folder Sublime Text\Packages\User

Link to comment
Share on other sites

Popcorn as a template engine in CodeIgniter

 

1) Download Popcorn Template Engine(http://popcorn.template-cms.org) and extract into \application\libraries\

 

2) Download Templates.zip and extract into \application\libraries\

 

Example:

2011-05-08_1935.png

 

3) Create folder for comiled templates \templates_c\ in the root

 

4) In the controller load the library.

$this->load->library('templates');

 

5) Use Popcorn Template Engine :)

$this->templates->assign('msg','Hello CI !');
$this->templates->draw('welcome_message');

Link to comment
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.