Awilum Posted May 7, 2011 Share Posted May 7, 2011 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! Quote Link to comment https://forums.phpfreaks.com/topic/235758-popcorn-the-flexible-fast-and-simple-template-engine-for-php/ Share on other sites More sharing options...
ignace Posted May 7, 2011 Share Posted May 7, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/235758-popcorn-the-flexible-fast-and-simple-template-engine-for-php/#findComment-1211860 Share on other sites More sharing options...
Awilum Posted May 7, 2011 Author Share Posted May 7, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/235758-popcorn-the-flexible-fast-and-simple-template-engine-for-php/#findComment-1211862 Share on other sites More sharing options...
ignace Posted May 7, 2011 Share Posted May 7, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/235758-popcorn-the-flexible-fast-and-simple-template-engine-for-php/#findComment-1211864 Share on other sites More sharing options...
Awilum Posted May 7, 2011 Author Share Posted May 7, 2011 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) Quote Link to comment https://forums.phpfreaks.com/topic/235758-popcorn-the-flexible-fast-and-simple-template-engine-for-php/#findComment-1211874 Share on other sites More sharing options...
ignace Posted May 7, 2011 Share Posted May 7, 2011 I do not see any problems for designers Then you are naïve! Quote Link to comment https://forums.phpfreaks.com/topic/235758-popcorn-the-flexible-fast-and-simple-template-engine-for-php/#findComment-1211878 Share on other sites More sharing options...
Awilum Posted May 7, 2011 Author Share Posted May 7, 2011 ignace yes I know that I must do some think with long echo {echo $language} .... Quote Link to comment https://forums.phpfreaks.com/topic/235758-popcorn-the-flexible-fast-and-simple-template-engine-for-php/#findComment-1211879 Share on other sites More sharing options...
Awilum Posted May 7, 2011 Author Share Posted May 7, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/235758-popcorn-the-flexible-fast-and-simple-template-engine-for-php/#findComment-1211883 Share on other sites More sharing options...
ignace Posted May 7, 2011 Share Posted May 7, 2011 I just looked at a simple example phptal and does not understand anything Оо Never wrote XHTML? You do know XML and XSLT, do you? Quote Link to comment https://forums.phpfreaks.com/topic/235758-popcorn-the-flexible-fast-and-simple-template-engine-for-php/#findComment-1211887 Share on other sites More sharing options...
Awilum Posted May 7, 2011 Author Share Posted May 7, 2011 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! Quote Link to comment https://forums.phpfreaks.com/topic/235758-popcorn-the-flexible-fast-and-simple-template-engine-for-php/#findComment-1211890 Share on other sites More sharing options...
Awilum Posted May 7, 2011 Author Share Posted May 7, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/235758-popcorn-the-flexible-fast-and-simple-template-engine-for-php/#findComment-1212068 Share on other sites More sharing options...
Awilum Posted May 8, 2011 Author Share Posted May 8, 2011 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: 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'); Quote Link to comment https://forums.phpfreaks.com/topic/235758-popcorn-the-flexible-fast-and-simple-template-engine-for-php/#findComment-1212488 Share on other sites More sharing options...
xtronic Posted May 16, 2011 Share Posted May 16, 2011 You should look around before naming your scripts. http://popcornphp.com/ Quote Link to comment https://forums.phpfreaks.com/topic/235758-popcorn-the-flexible-fast-and-simple-template-engine-for-php/#findComment-1216255 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.