By: Murat
Date: 2009-05-21
Time: 16:55
|
TBS tips for Smarty users
I was using Smarty on my projects. But I like TBS and want to use it on my next project. But I'm confused about doing my some Smarty routines on TBS.
1. On Smarty, I can set template variables with "assign" method. But in TBS I can't do this. I have lots of classes on my PHP projects and I don't use global variables. Can I set specifically my template variables without using global variables?
Smarty PHP:
$tpl->assign('key','value');
|
2 .On Smarty templates, I could use array variables with foreach without making anything from PHP(like running MergeBlock-like methods). This was good. Can I use array variables with blocks without running MergeBlock method on every variable assignments on TBS?
Smarty PHP:
class post {
public function show_posts(){
$posts = $this->get_last_posts(10); // Get last 10 posts
$tpl->assign('posts',$posts);
return $tpl->fetch('post_list.html'); // Get template result
}
}
.....
$tpl->assign('left_bar_content',$post->show_posts());
|
Smarty Template File:
{foreach from=$posts item=post}
<div class="post"><h3>{$post.post_title}</h3><p>{$post.post_content}</p></div>
{/foreach}
|
Altough, template file creator can want to do show first post only:
<div class="post"><h3>{$posts[0].post_title}</h3><p>{$posts[0].post_content}</p></div>
|
|
By: Skrol29
Date: 2009-05-22
Time: 00:01
|
Re: TBS tips for Smarty users
Hi Murat,
1) You can define data into the array $TBS->TplVars, and retrieve them using [var..tplvars.xxx]
Since TBS 3.5.0 (currently in beta RC), you can also assign data for manual or automatic MergeBlock() and MergeField(). TBS 3.5.0 beta is available at the download page.
2) It is possible since TBS 3.5.0 (same as above).
|
By: Murat
Date: 2009-05-22
Time: 01:23
|
Re: TBS tips for Smarty users
Hi Skrol29,
Thank you for your answer. I didn't analyze 3.5 version because of it is beta. But I'll analyze now for my needs. I think you are developer of TBS. What are known problems about 3.5 version and when will you publish stable version? Do you have a plan?
Thank you for this great job!
|
By: Skrol29
Date: 2009-05-22
Time: 11:23
|
Re: TBS tips for Smarty users
Hi Murat,
The last 3.5.0 version is a Release Candidate. It means it is quite stable. It has been tested, benched and discussed on the "TBS next" mailing list. All I need for a final release is 10 or 20 days without any bug report, and an updated documentation.
I think I made a bad answer for your point (2) :
A MergeBlock() is doing a loop on each record. And you cannot pick a record outside the block.
There is an exception: if you call MergeBlock() and there is fields without block defined (ie without parameter "block") then all fields are merged with the first record, and other records are not even fetched from the database. It can be nice, but a bad usage can make this a time eater.
There is also a trick to display only one picked item: define your block with only one conditional section which is filtering your item. Only this item will be displayed.
Smarty and TBS have not the same philosophy. Both have their advantages.
|
|
Posting in progress.
Please wait...
|