Categories > TinyButStrong general >

Mergefield with a method?

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: EllisGL
Date: 2008-07-25
Time: 21:23

Mergefield with a method?

I'm able to use the merge field method with a function name.
$TBS->MergeField('translate','translate',true);

But I'm not able to use it with an object method.
$TBS->MergeField('translate','$functions->translate',true);

I know that I can hack it to have a function that calles the object... but that seems a bit crappy..
By: Skrol29
Date: 2008-07-26
Time: 00:56

Re: Mergefield with a method?

Hi,

If the method can be called without any instance, then you can use:
$TBS->MergeField('translate','MyClass.TheMethod',true);

If the class need an instance, then you must use $TBS->ObjectRef to reference the instance, and then you can use:
$TBS->MergeField('translate','~TheMethod',true);
By: EllisGL
Date: 2008-07-26
Time: 01:30

Re: Mergefield with a method?

This what I did:
$TBS->ObjectRef['functions'] = &$functions;
$TBS->MergeField('translate','~functions.translate',true);

Work well! Thanks!