Categories > TinyButStrong general >

Problem with array

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Fu86
Date: 2004-11-21
Time: 17:24

Problem with array

$lang is an array:
[menu_home] => "Home"
[menu_news] => "News"
.....


[...]
$lang = parse_lang($global['language']);
$tpl->MergeBlock('lang', 'array', $lang);


template.html
.....eight="0">[lang.menu_home]</td>.....[lang.menu_news].....


Error:
TinyButStrong Error (Array value): Can't merge [lang.menu_home] because there is no key named 'menu_home'. This message can be cancelled using parameter 'noerr'.

I want to merge all lang.* fields in the template with the array-items.
By: Skrol29
Date: 2004-11-22
Time: 03:05

Re: Problem with array

This is because $leng is not an embeded array.
If you do $lang = array($lang);
then it works.

About multilanguage management, TBS has a smart feature for that.
Read the manual at the MergeField() method for more details.
By: TheIdeaMan
Date: 2004-12-14
Time: 15:24

Re: Problem with array

Skrol29,

The multilanguage management stuff does look nice for TBS. I'm currently working with an open source project that uses text strings to start the translation process. Rather than having a variable or constant to represent the string of text, they use the actual text as the lookup value.

<b><?php echo transFunction('Title of a Field'); ?></b>

Would there be anyway to do something like that with TBS?

There are people working on the project who are pushing for Smarty as the templating engine. Personally, I'd like to use something smaller. I've enjoyed using TBS on small test sites, and I think it could do well here and also get a good deal of press from this other project. Just an idea.

Thanks for your time.
By: Skrol29
Date: 2004-12-15
Time: 15:43

Re: Problem with array

Hi TheIdeaMan,

I can see only a twisted way to do your special multilanguage management with the last TBS version. An option that I'm cooking for next versions should make it possible but it is not ready yet.

Nevertheless, you can do it with current TBS version using a custom data functions and sub-block instead of fields.
Example:
  <mm>[transl.text;block=mm;p1='Text to translate']</mm>
   ...
  <mm>[transl.text;block=mm;p1='Another text to translate']</mm>

The PHP side must have a custom data function Set with the TBS syntax.
It should take the text to translate as the query and return only one record, with one column named 'text' which contains the translated text.
It is a bit twisted but it should work.
By: TheIdeaMan
Date: 2004-12-15
Time: 16:11

Re: Problem with array

That seems doable.

Thanks, Skrol. Your customer service is incredible. :)

I'm looking forward to more versions of TBS. My hope is to get it in use on the open source project I mentioned and possible on a small project of my own. It's been enjoyable to play with and I'm looking forward to putting it into practice.

The only other competitor that I've considered is the WACT template engine (http://wact.sourceforge.net/ ). However, I'd have to build the whole app in WACT and I'm not sure I'm up to that yet.

Thanks again for your help.
By: Skrol29
Date: 2004-12-16
Time: 12:24

Re: Problem with array

I didn't know WAST. But it seems to be a toolbox for Web Sites rather than a template engine. Even if it has some template features.

Enjoy TBS anyway :)

Something that could convince your team to use TBS is its code simplicity.
TBS is only one file, readable and commented. So it's easy to understand what it does and what goes wrong.
It's true that TBS has a ligth Support team (i'm looking for help), but in another hand the class is really simple and clear for a Php developer.
By: Skrol29
Date: 2004-12-28
Time: 18:22

Re: Problem with array

Hi TheIdeaMan,

In fact there is a simple issue to perform your special multilanguage support with TBS 2.0 (or higher).

HTML:
... [ml;text='Title of a Field'] ...

PHP:
$TBS->MergeField('ml','my_function',true);
...
function my_function($Name,&Parameters) {
  if (isset($Parameters['text'])) {
    return ... ;// translate value $Parameters['text']
  } else {
    return '?? Parameter text is missing ??';
  }
}

Explainations: custom functions for MergeField() already support an optional extra argument which gives access to the parameter list of the merged field. This is supported by TBS 2.0, but undocumented yet (my fault).

That is the key you need to simply do you special multi-language.
Enjoy,
By: TheIdeaMan
Date: 2004-12-29
Time: 16:08

Re: Problem with array

Excellent, Skrol29.

That will easily solve the language problems as well as open up some new doors for custom template fields for users.

You've done some amazing work. Thanks for sharing it with the rest of us.