Categories > TinyButStrong general >

different format last entry

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Roy
Date: 2007-08-29
Time: 11:16

different format last entry

Hello,

I'm trying to get the hang of TBS, and I have a question I couldn't find a clear (at least clear to me) answer in the forums.

Let's say I have an array with data (eg title and text) whitch I want to display. My html could look like this:
<p class="entry"><b>[blk1.title;block=p]</b><br />[blk1.text]</p>
And it would show the entry's. Now I want the last entry to be different (e.g. nof class "entry" but "entry_last") I read in the manual that there is a possibility to use if/then/else statements, but I didn't quite understand how they work, or if thsi could be used for this purpose in the first place...

Can anybody point me to the right direction with this?
By: Pirjo Posio
Date: 2007-08-30
Time: 03:16

Re: different format last entry

Hi Roy,
There is some text on if/then/else on the Support page of this Forum,
under the Golden Rules:
'If/then/else' are to be used for TBS fields.
The example there says:
[var.x;if [var.x]=1;then 'one']

This means, that when this TBS field is merged, TBS will replace this TBS field in the
template by the value of the PHP variable $x for each record --- except when the
value of the variable is number 1, then it will replace it with the string 'one'.

In your case, you will have to know when the last record is to be merged, for example by having a variable set. Then test that variable like var.x here.

I have an <ul><li>-list  - (Thank you Olivier, for your tabbed navbar tip on Tips&Tricks!)
<ul class="navlist">

<li class="borderline"><a class="[btab.0;if [val]='k';then 'current']" href="[btab.2;block=li]">[btab.1]</a></li>

</ul>

Here I use as the class of <a href> the value of key 0 in my array btab. These are normally 's', 'n','k'... and the html code will be
<a class="s" href=...>
or "n" etc.
but when the value is 'k' then it is
<a class="current" href=...>
 

I hope this helps.
By: rein
Date: 2007-08-30
Time: 11:11

Re: different format last entry

An easier solution might be to enhance your code as follows

<p class="entry[blk1.$; if [val]=[blk1.#;ope=add:-1]; then ' last'; else '']">
<b>[blk1.title;block=p]</b><br />[blk1.text]
</p>

I didn't test this code, so it could be you need to replace [blk1.#; ope=add:-1] to [var.last_key] or a hardcoded last key in the array.

In theory this solution should work perfectly if the array behind blk1 should have a numeric increasing key which you automaticlaly have if you use $arr[] = $val; for each value.
(I did do it like this a couple of times, but I did it in older TBS versions)

I hope this helps
By: Roy
Date: 2007-08-30
Time: 16:02

Re: different format last entry

Thanks for the posts! I'll have a test-run with these codes.

Like I said: I'm trying to get the hang of it, so if anybody else has another idea to do this, I'd like to hear that also. The more solutions, the better I'll understand the ways of TBS.