Jump to content

Archived

This topic is now archived and is closed to further replies.

Awilum

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

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!

 

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

ignace

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

 

And i think that this tags will be also  helpful {vars} {dump $var} may not be for a designer course.

 

And so the basic syntax for templates is in the Popcorn.

Share this post


Link to post
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.

Share this post


Link to post
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)

 

 

Share this post


Link to post
Share on other sites

ignace

yes I know that I must do some think with long echo {echo $language} ....

Share this post


Link to post
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>

 

Share this post


Link to post
Share on other sites

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

 

Never wrote XHTML? You do know XML and XSLT, do you?

Share this post


Link to post
Share on other sites

ignace

>Never wrote XHTML? You do know XML and XSLT, do you?

I think we talking about Designers or not ?))

 

>You do know...

Yes, but the designers do not!

Share this post


Link to post
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

Share this post


Link to post
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');

Share this post


Link to post
Share on other sites

×
×
  • 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.