Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

block

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Tips and Tricks
View previous topic :: View next topic  
Author Message
BloodRath
Smarty Rookie


Joined: 06 Jul 2003
Posts: 23
Location: France

PostPosted: Mon Jul 07, 2003 2:05 pm    Post subject: block Reply with quote

as i need some block ability for smarty : delete.... to use in my project (sql request coded in compile function which could delete some block if no result is shown) i just code one,
the bad news is u must define some object property .

i think it's perfectible, but it work if anyone interested....

anybody knows if block ability will be planned in smarty ?

blood
_________________
froggies forever.... Wink
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Mon Jul 07, 2003 7:23 pm    Post subject: Reply with quote

The API already supports block functions. Are you referring to block compiler functions? As you seem to be aware, you can simulate a block by registering both the opening and closing forms. There has been some recent activity on the dev-mailing list concerning this as well.

Greetings.
Back to top
View user's profile Send private message
BloodRath
Smarty Rookie


Joined: 06 Jul 2003
Posts: 23
Location: France

PostPosted: Sat Jul 12, 2003 1:09 am    Post subject: Reply with quote

thanx,
cool i will check dev-mailing
but excuse me perhaps i have done a mistake in reading the api but i haven't seen block management (except the management of the type : block himself)
i have succeed in manage blocks of html data from template (delete one of them when a event occur), but i think i will need sometimes to manage them from the php script which call the template, it seem to be a bit more complicated, i think i'll use some globals orders which must be read when setting up the block in the template like this :

in php : send order to block 1 to be deleted
in template when i set up the block i read the stack of order and apply them

what do u think about it?
_________________
froggies forever.... Wink
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sat Jul 12, 2003 3:23 am    Post subject: Reply with quote

Hi.

Sorry but I think I am having trouble following what you are trying to do. Perhaps I mistook your original query as well. Perhaps a code example will clear things up?
Back to top
View user's profile Send private message
BloodRath
Smarty Rookie


Joined: 06 Jul 2003
Posts: 23
Location: France

PostPosted: Sun Jul 13, 2003 2:12 pm    Post subject: Reply with quote

i think it's my bad english which is in fault Wink
i wanna manage this type of thing

in tpl

<!-- result block -->
<block id="result_0">
<!-- proceed with them -->
{section name=article loop=$lstArticle}
<div class="row">
<span class="col_1_2">id_article</span>
<span class="col_2_2">{$lstArticle[article].id_article}</span>
<span class="col_1_2">titre</span>
<span class="col_2_2">{$lstArticle[article].titre}</span>
<span class="col_1_2">statut</span>
</div>
{/section}
</block>

<block id="no_result_0">
it seems that there is no data
</block>

in my php script in launch a sql request, which leads to no result, i would like to delete the block which handle the result in the template.

on the other hand if the request will return any result, i would delete the no_result block in the template

i know i could achieve it in the template form, but i think
- it's not the designer work to deals with if and endif test resulting from my php code,
- it's a long work always to deal with those if endif, i would achieve it automatically

i succeed in create some compiler function which deal with block destruction (but in those cases i must include the sql query in the smarty compiler function), i would like to achieve it from the php code which call the template. i have some idea but prefer to know if it will be developped before i start to modify smarty code.

thanx
_________________
froggies forever.... Wink
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed Jul 16, 2003 8:30 am    Post subject: Reply with quote

Hi BloodRath.

It sounds like you are looking for {sectionelse}

From the documentation for section,sectionelse:

Quote:
Example 7-20. sectionelse
Code:
{* sectionelse will execute if there are no $custid values *}
{section name=customer loop=$custid}
   id: {$custid[customer]}<br>
{sectionelse}
   there are no values in $custid.
{/section}


Similarly, {foreach} has a corresponding {foreachelse}.

HTH
Back to top
View user's profile Send private message
BloodRath
Smarty Rookie


Joined: 06 Jul 2003
Posts: 23
Location: France

PostPosted: Sat Jul 19, 2003 8:22 pm    Post subject: Reply with quote

thanx for help it could be what i need but ...

just one thing it seem to me that all code in section before the section else was not displayed, but in my example i could also delete item before the foreach section start (row header by example).

am i wrong ?

Greetings.
_________________
froggies forever.... Wink
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sat Jul 19, 2003 9:07 pm    Post subject: Reply with quote

BloodRath, I'm not sure I followed you but if you are right in saying that the ONLY ONE of the {section} or {sectionelse} blocks will get executed depending on whether there is anything to loop over or not.

If you need more elaborate decision checking than that or more fine-grained control of what blocks portions to display, then you will either have to resort to if/else blocks as you have surmised earlier or write your own custom loop blocks using the plugin API.
Back to top
View user's profile Send private message
BloodRath
Smarty Rookie


Joined: 06 Jul 2003
Posts: 23
Location: France

PostPosted: Mon Jul 21, 2003 10:20 am    Post subject: Reply with quote

thanx for all, i so continue to write one,

blood
_________________
froggies forever.... Wink
Back to top
View user's profile Send private message
pix0r
Smarty n00b


Joined: 08 Sep 2003
Posts: 1
Location: Southern Orange County

PostPosted: Mon Sep 08, 2003 11:50 pm    Post subject: Reply with quote

I'm not sure if you answered blood's original question or not. Regardless, I'm looking for something similar (at least the way I interpreted the question).

There are many cases in which I don't want the template (or template designer) to deal with logic. Perhaps I'm going about things the wrong way, but I'm used to using phplib templates, which are based entirely on blocks, and these blocks are always controlled from the PHP script.. I choose which blocks to show and how many times to show them.

Is there any way to do something similar with Smarty templates?

Say I have an error block that is shown only when there is an error condition. Is there any way for me to trigger this block from PHP? Or do I need to put the logic (if statement or whatever) inside the actual template?

Sorry if this is obvious.. seemed to me it should be easy to find a way to do this, but I haven't yet.

Thanks,
Mike
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Tips and Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP