Home
Download
Add-ons
Help
Forum
Organisation
Project
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email?
February 12, 2012, 04:05:31 AM
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Search:
Advanced search
Interested in joining the WebsiteBaker team?
For more Information read
here
or on our
new website
.
149621
Posts in
21098
Topics by
7537
Members
Latest Member:
lotte2
WebsiteBaker Community Forum
English
Modules
(Moderator:
Argos
)
Upcoming: Template Engine (x_FastTemplate2 compatible)
Pages: [
1
]
2
Go Down
Author
Topic: Upcoming: Template Engine (x_FastTemplate2 compatible) (Read 3825 times)
WebBird
Guest
Upcoming: Template Engine (x_FastTemplate2 compatible)
«
on:
September 15, 2009, 02:50:41 PM »
After some playing around with Aldus' very nice x_FastTemplate2 (
http://www.websitebakers.com/pages/libs/x_fasttemplate2.php
), I decided to create my very own Template engine to have some more options than x_FastTemplate2. (Unfortunately, to enhance x_FastTemplate2 is not an option, in the end it would be a complete rewrite anyway.)
The new wbTemplate class will be used in an upcoming new module, but I'm going to port all my modules later.
Create an instance (example):
Code:
<?php
require_once
dirname
(
__FILE__
).
'/../../wblib/class.wbTemplate.php'
;
$tpl
= new
wbTemplate
();
?>
Set start and end tag (Default: {{ }}):
Example: <!-- var --> instead of {{ var }}
Code:
<?php
$tpl
= new
wbTemplate
(
array(
'start_tag'
=>
'<!--'
,
'end_tag'
=>
'-->'
)
);
?>
Set template path:
Code:
<?php
$tpl
->
setPath
( <
path
> );
?>
(Default:
<Current dir>/templates
)
Set current template to work with:
Code:
<?php
$tpl
->
setFile
( <
file
> );
?>
Alias:
setTemplate()
Parse template (template name already set with
setFile()
)
Code:
<?php
$tpl
->
parseTemplate
( array(
'var'
=>
'Some content'
) );
?>
Parse template (template name
not
already set or different):
Code:
<?php
$tpl
->
getTemplate
( <
file
>, array(
'var'
=>
'Some content'
) );
?>
Template Markup
{{ var }}
Replaces {{ var }} with 'Some Content' (see above)
{{ :if var }}<div>{{var}}</div>{{ :ifend }}
Replaces {{ var }} if there's some content for {{ var }}; removes complete block if {{ var }} is not set. (Nice for optional content you don't want to leave empty HTML if it's missing.)
Of course, there can be any content within {{ :if }}...{{ :ifend }}
{{ :loop var }} {{ var }} {{ :loopend }}
Replaces {{ var }} in a loop, which means that there must be an array given for {{ var }}. Of course, you can have multiple {{ placeholders }} in the loop.
Of course, there can be any content within {{ :loop }}...{{ :loopend }}
Combining conditionals:
(v0.7)
You can combine conditional statements with 'AND' (&&) or 'OR' (||).
Code:
{{ :if prevlink || nextlink }}
<tr>
<td colspan="4">{{ prevlink }}</td>
<td colspan="3" style="text-align: right;">{{ nextlink }}</td>
</tr>
{{ :ifend }}
In this example, the block will be removed if neither 'prevlink' nor 'nextlink' are set.
Comments:
(v0.4)
There are to ways to include template comments, which will be removed completely when the template is parsed:
Code:
{{ :comment This will be removed }}
<!-- BEGIN template comment -->
This will be removed also
<!-- END template comment -->
See discussion below for more details.
Including other templates:
(v0.05)
Code:
{{ :include template_file.htt }}
The file will be searched in the current template path. Placeholders in included templates will work as expected.
Handling unresolved placeholders:
The default behaviour is to print an error message and exit if there are unresolved placeholders. You can alter this using the
setBehaviour()
method. The alternatives are:
* Replace with HTML comments ->
$tpl->setBehaviour( 'comment' )
* Remove ->
$tpl->setBehaviour( 'remove' )
* Fail with error (default) ->
$tpl->setBehaviour( 'fail' )
Known issues:
* Cycles that can arise when including templates that include each other again are not intercepted yet.
This is work in progress, so I'm sure there's more to come.
Feel free to let me know your thoughts and suggestions.
You may also like to have a look at the FormBuilder helper class -
http://www.websitebaker2.org/forum/index.php/topic,15206.msg97649.html#msg97649
AMASP Link:
http://www.websitebakers.com/pages/libs/wblib.php?lang=EN
«
Last Edit: November 17, 2009, 06:32:25 PM by WebBird
»
Logged
Stefek
WebsiteBaker Org e.V.
Offline
Posts: 4753
Re: Upcoming: Template Engine (x_FastTemplate2 compatible)
«
Reply #1 on:
September 15, 2009, 03:56:28 PM »
Hello WebBird.
It looks very promising.
I played around with lots of template libraries lately including PHPLib, x-template, fast-template, x-fast-template, smarty...
Allthough I have to use Smyrty for some projects (like xt-commerce) I don't really like it.
PHPLib and x-fastTemplate is fine with me in the meanwhile, but I am really missing a clear block handling like yours:
{{ :if var }}<div>{{var}}</div>{{ :ifend }}
This could be a really handy library.
Question: will it be usable without WB too?
And, is that doable like {my_var} instead of {{ my_var }} too?
Kind regards,
Stefek
Logged
"In a time of universal deceit, telling the truth becomes a revolutionary act."
- George Orwell, Nineteen eighty-four (1984)
WebBird
Guest
Re: Upcoming: Template Engine (x_FastTemplate2 compatible)
«
Reply #2 on:
September 15, 2009, 04:03:32 PM »
Quote from: Stefek on September 15, 2009, 03:56:28 PM
Question: will it be usable without WB too?
Yepp.
Quote from: Stefek on September 15, 2009, 03:56:28 PM
And, is that doable like {my_var} instead of {{ my_var }} too?
I'm going to make the start and end tags configurable, so you can also use <!-- var -->. (Edit: Done. See first Posting for details.)
«
Last Edit: September 15, 2009, 04:21:38 PM by WebBird
»
Logged
Stefek
WebsiteBaker Org e.V.
Offline
Posts: 4753
Re: Upcoming: Template Engine (x_FastTemplate2 compatible)
«
Reply #3 on:
September 15, 2009, 04:05:24 PM »
Cool, cool.
Regards,
Stefek
Logged
"In a time of universal deceit, telling the truth becomes a revolutionary act."
- George Orwell, Nineteen eighty-four (1984)
mr-fan
Offline
Posts: 1538
Re: Upcoming: Template Engine (x_FastTemplate2 compatible)
«
Reply #4 on:
September 16, 2009, 07:54:52 PM »
hi bianka,
just have the time for some short questions....
1. xft2 compatible means all features from xft2 where also available in wblib? getbyblock - getbytemplate - getbysequence ?
2. are there a special place for new functions (see pm for the function code...) for capture a section or a whole page :
Code:
<?php
//dau codings call xft2 section
'globalsection'
=>
$xft2
->
capture_echo
(
"show_section(66);"
),
3. or "include" you such functions in the mod itself?
4. have you a error reporting for template engine issues like template-file setup/data checking or such things?
"you don't set up a correct template file...." or if just a few or one template file is not correct - to find this faster...?
just asking - i don't know much about template engings like stefek! i just played a little with xft2.....
looking straight forward to your modul - if it is "dummyfriendly" like xft2 i will provide some templates....
regards martin
Logged
Stefek
WebsiteBaker Org e.V.
Offline
Posts: 4753
Re: Upcoming: Template Engine (x_FastTemplate2 compatible)
«
Reply #5 on:
September 16, 2009, 09:17:16 PM »
Quote from: mr-fan on September 16, 2009, 07:54:52 PM
just asking - i don't know much about template engings like stefek! i just played a little with xft2.....
Oh.. I'm not, I'm not so well skilled with all of them. All I learnd here is from questioning Thorn, Doc and using the Module Primer.
With Smarty I had a lot to do because of my designer work.
But, I am very interested in a good Library which is easier to set up as phpLib and not so overwhelming as Smarty. Something in between of them... but with the possibility to use Blocks, Loops in a handy manner.
I think WebBird is making a good job here.
BTW, WebBird, will you have a "internal comment" call right in the class. Something like Smarty use to have?
There you have {* not executed comments, just for internal comments in your template *}
More Info:
http://www.smarty.net/manual/en/language.basic.syntax.php
Regards,
Stefek
Logged
"In a time of universal deceit, telling the truth becomes a revolutionary act."
- George Orwell, Nineteen eighty-four (1984)
WebBird
Guest
Re: Upcoming: Template Engine (x_FastTemplate2 compatible)
«
Reply #6 on:
September 17, 2009, 10:59:06 AM »
Quote from: mr-fan on September 16, 2009, 07:54:52 PM
1. xft2 compatible means all features from xft2 where also available in wblib? getbyblock - getbytemplate - getbysequence ?
Not for now. The goal is not to do this "by hand" (for example, get a loop by calling get_by_sequence), but only put all the data in a structured array and then call parseTemplate() or printTemplate() and you're ready.
I _could_ implement xft2 compatible function calls for easy switching, but I'm not going to force out xft2.
So, "xtf2 compatible" means "template markup", not "function calls".
Quote from: mr-fan on September 16, 2009, 07:54:52 PM
2. are there a special place for new functions (see pm for the function code...) for capture a section or a whole page :
Code:
<?php
//dau codings call xft2 section
'globalsection'
=>
$xft2
->
capture_echo
(
"show_section(66);"
),
I'm planning to implement something like this.
Quote from: mr-fan on September 16, 2009, 07:54:52 PM
4. have you a error reporting for template engine issues like template-file setup/data checking or such things?
"you don't set up a correct template file...." or if just a few or one template file is not correct - to find this faster...?
Yes, of course. All modules including the template engine throw fatal errors on - well, fatal errors.
"Fatal" means: no template file name given, template path / file does not exist, and so on. But on the other hand, most errors that are not vital are suppressed. But - you can enable internal debugging to see what's going on.
Logged
WebBird
Guest
Re: Upcoming: Template Engine (x_FastTemplate2 compatible)
«
Reply #7 on:
September 17, 2009, 11:00:58 AM »
Quote from: Stefek on September 16, 2009, 09:17:16 PM
BTW, WebBird, will you have a "internal comment" call right in the class. Something like Smarty use to have?
I have nothing planned like this. But if you can show/convince me that it's a vital function, I can add it.
Logged
Stefek
WebsiteBaker Org e.V.
Offline
Posts: 4753
Re: Upcoming: Template Engine (x_FastTemplate2 compatible)
«
Reply #8 on:
September 17, 2009, 01:29:29 PM »
Quote from: WebBird on September 17, 2009, 11:00:58 AM
Quote from: Stefek on September 16, 2009, 09:17:16 PM
BTW, WebBird, will you have a "internal comment" call right in the class. Something like Smarty use to have?
I have nothing planned like this. But if you can show/convince me that it's a vital function, I can add it.
OK,let me try.
Good implementation would be using a markup like:
{BEGIN template comment}
<p>bladibladiblblublu</p>
{END template comment}
and cause/force the template parser to not show this in the output (the HTML Structure while the page is running).
Of course you can use <!-- & --> to do this, but it will be shown in the HTML Output anyway.
And the template comment can be used for commenting out your HTML and/or Template descriptions like:
{BEGIN template comment}
---- Template for BLA Module
{END template comment}
There is one mor advantage while working on Templates.
You can set a path to a css file, the css file will work in wysiwyg mode, so you can adjust your templates very handy.
Inside the internal comment it will not show in the final output (while running the page).
Working with the standard index.php I am using a call like this to achieve this:
Code:
<?php
// "template engine" CSS File inclusion
if (
file_exists
(
'http://localhost/favicon.ico'
)) {
// see if file exists, if true, you on your xampp environment
?>
<link type="text/css" href="screen.css" rel="stylesheet" media="screen" />
<?php
}
?>
In this way my WYSIWYG will be influenced by the CSS File.
I don't need to delete this Link before uploading the whole template to a live server. It won't be linked anyway.
For the template class I would like to have this.
It would be cool, if there could be two kinds of calls for comments:
1) like {BEGIN template comment} {/BEGIN template comment}
2) the second like <!-- BEGIN template comment --><!-- END template comment -->
The second one is good if you don't want to display the code in the final output AND your WYSIWG Mode.
I would be glad if you implement something like this.
If you want to implement just one, then I would preferre the second one. For you can then comment out your HTML sections very easy. (It won't link to external files being shown in WYSIWYG Mode then, but this is not the big disadvantage. )
Kind Regards,
Stefek
Logged
"In a time of universal deceit, telling the truth becomes a revolutionary act."
- George Orwell, Nineteen eighty-four (1984)
WebBird
Guest
Re: Upcoming: Template Engine (x_FastTemplate2 compatible)
«
Reply #9 on:
September 17, 2009, 03:17:28 PM »
I'm not sure that I understand the difference in behaviour of the two implementations.
Do you mean that:
Code:
<!-- BEGIN template comment -->
<?php
if (
file_exists
... ) ...
?>
<!-- END template comment -->
would be removed in the frontend (for the template uses wblib template engine), but stay in place in the backend (for it does NOT use wblib template engine)? And because it's a valid HTML comment, it causes no problems either way?
Logged
WebBird
Guest
Re: Upcoming: Template Engine (x_FastTemplate2 compatible)
«
Reply #10 on:
September 17, 2009, 03:26:07 PM »
Please see
http://www.websitebaker2.org/forum/index.php/topic,15206.msg98376.html#msg98376
for preview version for download.
Logged
Stefek
WebsiteBaker Org e.V.
Offline
Posts: 4753
Re: Upcoming: Template Engine (x_FastTemplate2 compatible)
«
Reply #11 on:
September 17, 2009, 06:56:41 PM »
Hello Bianca..
oh no, no.. this is a misunderstanding.
For current templates (the standard wb templates) I am using this snippet in order to have the css loaded while I am working off line. I have then a full WYSIWYG access in my Editor.
I will try to explain better later tonight what I mean.
Have a load things to accomplish right now.
Best regards,
Stefek
Logged
"In a time of universal deceit, telling the truth becomes a revolutionary act."
- George Orwell, Nineteen eighty-four (1984)
Stefek
WebsiteBaker Org e.V.
Offline
Posts: 4753
Re: Upcoming: Template Engine (x_FastTemplate2 compatible)
«
Reply #12 on:
September 19, 2009, 05:18:59 PM »
Hello Bianca,
as I mentioned in my PM, I was too fast, and absolutely wrong with my "feature Request" for 2 different comment block markers.
If there is any chance to implement it exactly like this:
<!-- BEGIN template comment --><!-- END template comment -->
...then it would be great.
Kind regads,
Stefek
Logged
"In a time of universal deceit, telling the truth becomes a revolutionary act."
- George Orwell, Nineteen eighty-four (1984)
WebBird
Guest
Re: Upcoming: Template Engine (x_FastTemplate2 compatible)
«
Reply #13 on:
September 20, 2009, 08:06:10 PM »
Well, maybe...
Logged
Stefek
WebsiteBaker Org e.V.
Offline
Posts: 4753
Re: Upcoming: Template Engine (x_FastTemplate2 compatible)
«
Reply #14 on:
September 20, 2009, 08:11:19 PM »
... chocolate, I guess
KR,
Stefek
Logged
"In a time of universal deceit, telling the truth becomes a revolutionary act."
- George Orwell, Nineteen eighty-four (1984)
WebBird
Guest
Re: Upcoming: Template Engine (x_FastTemplate2 compatible)
«
Reply #15 on:
September 21, 2009, 09:57:06 AM »
No, I'm not corrupt.
It's more a matter of time and popular demand.
Logged
Stefek
WebsiteBaker Org e.V.
Offline
Posts: 4753
Re: Upcoming: Template Engine (x_FastTemplate2 compatible)
«
Reply #16 on:
September 21, 2009, 11:00:30 AM »
All right.
I got it.
Wasn't meant this way... (more fo inspirational purposes.)
Kind regards,
Stefek
Logged
"In a time of universal deceit, telling the truth becomes a revolutionary act."
- George Orwell, Nineteen eighty-four (1984)
WebBird
Guest
Re: Upcoming: Template Engine (x_FastTemplate2 compatible)
«
Reply #17 on:
September 21, 2009, 04:45:08 PM »
Well, the english "corrupt" sounds a bit harder than the german "bestechlich", which was meant as a joke.
Edit:
I created a markup for "simple comments", which will be removed completely.
Code:
{{ :comment This will be completely removed }}
{{ :comment
Also multiline
of course
}}
(Opening ({{) and closing (}}) tags can be overridden.)
«
Last Edit: September 21, 2009, 04:55:02 PM by WebBird
»
Logged
Stefek
WebsiteBaker Org e.V.
Offline
Posts: 4753
Re: Upcoming: Template Engine (x_FastTemplate2 compatible)
«
Reply #18 on:
September 21, 2009, 04:56:40 PM »
Quote from: WebBird on September 21, 2009, 04:45:08 PM
Well, the english "corrupt" sounds a bit harder than the german "bestechlich", which was meant as a joke.
OK, WebBird.
However, I am glad if here is such a marker.
I can't talk for the general interest...
For the moment I am also too busy (sorry) to test your class as it is now.
I hope more developers will say something about our efforts.
Sincerely,
Stefek
Logged
"In a time of universal deceit, telling the truth becomes a revolutionary act."
- George Orwell, Nineteen eighty-four (1984)
WebBird
Guest
Re: Upcoming: Template Engine (x_FastTemplate2 compatible)
«
Reply #19 on:
September 21, 2009, 05:23:54 PM »
Both comment styles are included now.
Alt1:
Code:
{{ :comment This will be removed }}
Opening and closing tags can be overridden.
Alt2:
Code:
<!-- BEGIN template comment -->
This will be removed
<!-- END template comment -->
Opening and closing tags
cannot
be overridden.
Logged
Stefek
WebsiteBaker Org e.V.
Offline
Posts: 4753
Re: Upcoming: Template Engine (x_FastTemplate2 compatible)
«
Reply #20 on:
September 21, 2009, 05:33:30 PM »
Awesome!
Thank you very much, Bianca.
I will test your Template Class as fast as I can.
Best Regards,
Stefek
Logged
"In a time of universal deceit, telling the truth becomes a revolutionary act."
- George Orwell, Nineteen eighty-four (1984)
WebBird
Guest
Re: Upcoming: Template Engine (x_FastTemplate2 compatible)
«
Reply #21 on:
September 21, 2009, 05:47:06 PM »
You should wait until I uploaded the new version....
Logged
Stefek
WebsiteBaker Org e.V.
Offline
Posts: 4753
Re: Upcoming: Template Engine (x_FastTemplate2 compatible)
«
Reply #22 on:
September 21, 2009, 06:01:40 PM »
You're right...
Logged
"In a time of universal deceit, telling the truth becomes a revolutionary act."
- George Orwell, Nineteen eighty-four (1984)
mr-fan
Offline
Posts: 1538
Re: Upcoming: Template Engine (x_FastTemplate2 compatible)
«
Reply #23 on:
September 21, 2009, 06:30:11 PM »
will testing too....!
i've got a little timehole next two weeks....for you! if you are working now on this engine before you finishing EM i will check out this template engine - that is also a real great addition for website baker!!
best wishes
martin
Logged
WebBird
Guest
Re: Upcoming: Template Engine (x_FastTemplate2 compatible)
«
Reply #24 on:
September 21, 2009, 06:47:47 PM »
Update available here:
http://www.websitebaker2.org/forum/index.php/topic,15206.msg98376.html#msg98376
No output capturing yet!
I mean something like this:
Code:
<?php
'globalsection'
=>
$xft2
->
capture_echo
(
"show_section(66);"
),
?>
Logged
Pages: [
1
]
2
Go Up
Jump to:
Please select a destination:
-----------------------------
General
-----------------------------
=> General Announcements
-----------------------------
English
-----------------------------
=> Help & Support
-----------------------------
General
-----------------------------
=> WebsiteBaker Website Showcase
-----------------------------
English
-----------------------------
=> Modules
=> Templates, Menus & Design
=> WebsiteBaker Language Files
=> Droplets (PHP code for use with Droplet module) & Snippets (raw PHP code)
-----------------------------
General
-----------------------------
=> Guest Area & Off-Topic
-----------------------------
English
-----------------------------
=> WebsiteBaker 2.x discussion
=> WebsiteBaker 3
-----------------------------
General
-----------------------------
=> Security Announcements
-----------------------------
Deutsch (German)
-----------------------------
=> Hilfe/Support
-----------------------------
General
-----------------------------
=> Documentation
-----------------------------
Francais (French)
-----------------------------
=> Help/Support
-----------------------------
Italiano (Italian)
-----------------------------
=> Help/Support
-----------------------------
Deutsch (German)
-----------------------------
=> Ankündigungen
=> Diskussion über WB
=> Off-Topic
=> Archiv für Themen bis 2007
=> Module & Snippets
-----------------------------
English
-----------------------------
=> Archive (posts up to 2007)
-----------------------------
Nederlands (Dutch)
-----------------------------
=> Aankondigingen
=> Hulp & Ondersteuning
=> Niet-Terzake (Off Topic)
-----------------------------
Deutsch (German)
-----------------------------
=> jQuery
=> Tutorials
=> Templates & Design
-----------------------------
English
-----------------------------
=> jQuery
-----------------------------
Bakery (WB shop module)
-----------------------------
=> Bakery English
=> Bakery Deutsch
-----------------------------
English
-----------------------------
=> WebsiteBaker 2.9
===> Announcements
===> Help/Support
===> Suggestions
-----------------------------
Deutsch (German)
-----------------------------
=> WebsiteBaker 2.9
===> Ankündigungen
===> Hilfe/Support
===> Vorschläge
-----------------------------
English
-----------------------------
===> Software bugs
-----------------------------
Deutsch (German)
-----------------------------
===> Softwarefehler
=====> Module / Extensions
-----------------------------
English
-----------------------------
=====> Modules / Extensions
-----------------------------
Deutsch (German)
-----------------------------
===> Erfahrungs und Testberichte
-----------------------------
KeepInTouch (Multi Contact Module)
-----------------------------
=> KeepInTouch English
=> KeepInTouch Deutsch
Loading...