Categories > TinyButStrong general >

mtype for attributes?

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: TheIdeaMan
Date: 2005-02-16
Time: 20:42

mtype for attributes?

Is it possible to have an attribute displayed only if the field inside of it is merged successfully? Perhpas something similar to magnet and mtype only for attributes?

I have an array that looks something like this:

Array (
    [0] => Array (
                  [id] => 3
                  [text] => product name
                  [in_cart] => 1
               )
    [1] => Array (
                  [id] => 2
                  [text] => chicken
               )
)

I'd like to merge a block with this array and have an attribute (for instance "class") set on any of the products that have the "in_cart" key set to 1 (I can change the array to set the "in_cart" value to '0' if necessary).

Perhaps something like this:
<table>
<tr>
  <td class="[product.in_cart;when [val]=1]in_cart">[product.text;block=table]</td>
</tr>
</table>


I think I'm off on a few things. Just wondering if something like this would be possible.

Thanks.
By: Skrol29
Date: 2005-02-17
Time: 00:24

Re: mtype for attributes?

Hi,

This should work:
<td [product.in_cart;noerr;if [val]!='';then 'class="[val]"']>

Note: parameter 'when' is only for [onload] or [onshow] blocks (TBS 2.0 and 2.01).
By: TheIdeaMan
Date: 2005-02-17
Time: 02:52

Re: mtype for attributes?

Thanks, Skrol29, as always.

So, one can use any field params on a block field? That makes since. Sorry I didn't research it more.

Would you ever consider changing the mtype/magnet params to include one for attributes? That would keep the XHTML valid.

The code could looks something like:
<td class="[product.in_cart;mtype=attribute;magnet=class">

In the example above the "magnet" parameter is probably not needed since it would be redundant next to the "mtype=attribute" parameter.

Just an idea.
By: Skrol29
Date: 2005-02-17
Time: 03:21

Re: mtype for attributes?

That's not a bad idea. Making valid XHTML templates is nice.
I will see if it's easy to do.
Founding the attribute before seems easy, but the pair of double quote is maybe more difficulte as it seems.
By: TheIdeaMan
Date: 2005-02-17
Time: 14:31

Re: mtype for attributes?

Skrol29,

I haven't studied out how TBS does its parsing, but would it not be possible to look for the first space to the left and either the first space or first ">" to the right? That might avoid the double quote problem altogether.

You would know better of course.

Thanks for considering the idea, Skrol29.
By: Skrol29
Date: 2005-02-17
Time: 17:24

Re: mtype for attributes?

  > the first space to the left
And what if the man code it (att = "value") with spaces?

  >first space or first ">" to the right?
And what if the man code it with other attributes after this one?

It looks like possible but not such simple.
I'll study this because the feature is nicelly interesting.
By: kapouer
Date: 2006-06-01
Time: 15:42

Re: mtype for attributes?

have you considered implementing this feature or not ?
may i help ?
By: kapouer
Date: 2006-06-01
Time: 16:02

Re: mtype for attributes?

By the way, while attempting the solution you propose, i got some weird behaviour (i guess it is normal, but not very clearly documented in the manual ?)

<span [page.next;if [val.next]!='';then 'class="[val]"';else '']>toto</span>

where
$fPage = array("next" => "index.php");
for example
and
$TBS->MergeField('page', $fPage);

this works !
but
if [val.next]
is unexpected,
and in contradiction with the semantics of
class="[val]"

i got the point : being able to access the field array so we can make tests on other columns.
in this case, this should be DOCUMENTED SOMEWHERE. Or i missed it ?

hope this helps improvement
By: kapouer
Date: 2006-06-01
Time: 16:08

Re: mtype for attributes?

oops
sorry it doesn't work at all.

i don't get it, something doesn't work with array fields
By: Skrol29
Date: 2006-06-01
Time: 16:17

Re: mtype for attributes?

Hi,

Yes it can be implemented and probably will.
I've coded a function for the Excel plug-in which can read XML attributes of any tag.
This function can now be inserted into the HTML plug-in in order to provide your feature easily. The best way is to give it via parameter "ope". This parameter is to be preferred for parameter enhancement via plug-ins.

I cannot tell when I will do it because I have to do another plug-in before (not big).
By: Skrol29
Date: 2006-06-01
Time: 16:18

Re: mtype for attributes?

I was suprised it could work. [val] is just a keyword for TBS (event if its separators change with TBS tag separators).
By: kapouer
Date: 2006-06-01
Time: 16:32

Re: mtype for attributes? but why this doesn't work ?

[var.pagenext;if [val]!='';then 'tata']

where $pagenext = "toto";

this doesn't outputs tata

any clue ? i guess it's my syntax ?

thanks for your help
By: Skrol29
Date: 2006-06-01
Time: 16:43

Re: mtype for attributes? but why this doesn't work ?

> [var.pagenext;if [val]!='';then 'tata']

Are you sure that $pagenext is set before this TBS tag is processed ?
By: kapouer
Date: 2006-06-01
Time: 16:51

Re: mtype for attributes? but why this doesn't work ?

this is not my day...
it works, BUT in my case it doesn't work :
in html :
[var.pagenext;if [val]!='';then 'tata']


in php :
$pagenext = "index.php?ua=oml&pg=4";
// this echoes 'index.php?ua=oml&amp;pg=4'
$pagenext = "toto";
// this echoes 'tata'

first case is not desired !
By: kapouer
Date: 2006-06-01
Time: 17:02

Re: mtype for attributes? but why this doesn't work ?

if i don't put equal (=) chars in my string it works...
By: Skrol29
Date: 2006-06-01
Time: 17:02

Re: mtype for attributes? but why this doesn't work ?

Before TBS 3.0, default value for parameter "esle" is '' (empty string).
I know this looks strange, but it used to had a sens in TBS 1.x.
  :/
The behavior in not the same in TBS 3.0.

You should code:
[var.pagenext;if [val]!='';then 'tata';else [val]]


By: kapouer
Date: 2006-06-01
Time: 17:16

Re: mtype for attributes? it works !!!

that's the right syntax for me :

[var.pagenext;if [val]='';then '';else nexthref="[val]"]

change anything and it doesn't work...
By: Skrol29
Date: 2006-06-01
Time: 17:26

Re: mtype for attributes? it works !!!

You last snippet works fine for me. With both TBS 3.0 and 2.05.