Categories > TinyButStrong general >

getting mergeField to work?

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: starmonkey
Date: 2005-11-20
Time: 21:50

getting mergeField to work?

hi - trying some simple stuff with tbs, and I can't get it to work.

in my code I have:

$TBS->MergeField('account',array('id'=>55,'name'=>'Bob', 'test' => 'blahblahyay'));

and in my html I have:

welcome home, <b>[account.name]</b>

but all I see is:

welcome home, [account.name]

? I'm confused. I can easily make the structure global and see it through:

welcome home, <b>[var.account.name]</b>

but I'd prefer the brevity. help?
By: Skrol29
Date: 2005-11-20
Time: 23:02

Re: getting mergeField to work?

Hi starmonkey,

It should work. I've tested your snippet (just in case...) and no problem with me.

Did you take care that the $TBS->MergeField() line must be after the
  $TBS->LoadTemplate(...)
and before the
  $TBS->Show(...)
?
By: starmonkey
Date: 2005-11-20
Time: 23:51

Re: getting mergeField to work?

thanks - that works. it might be good to add a note to the mergeField documentation, to help head scratching?

thanks,
sm
By: Skrol29
Date: 2005-11-21
Time: 00:35

Re: getting mergeField to work?

It's not said explicitely in the manual but it's so logical (TBS logic).
TBS merging commands apply on the loaded template, and Show() ends the current script.
By: ClausVB
Date: 2005-11-21
Time: 23:40

Re: getting mergeField to work?

> it might be good to add a note
> to the mergeField documentation,
> to help head scratching?

Perhaps you missed it, but there is documentation in the manual and on my site
http://lamp.clausvb.de/tbs_mhtml/crashcourse/sec02_simple_example.html
which shows a simple example. This crash course will get bigger and someday a tutorial.

It says:
---
Method "LoadTemplate" will load "tmpl/basic.htm" in this example. It contains your HTML code and all your variables (aka TBS fields). Method "Show" will display HTML and merged variables on your screen. "Show" will end the script. Therefore you should not use the functions echo() or print() afterwards.
---

Regards,
Claus
By: leo.b
Date: 2006-11-17
Time: 05:56

Re: getting mergeField to work?

I have same problem but the case is little bit different.

i have a template like this:
main.htm
Helo, you are here ...
[onload;file=[var.file_include]]

sub.htm
This is sub folder
[var.gender]

my php script is
index.php
global $gender;

$gender = "M";
$TB->LoadTemplate("main.htm");
include("modul.php");
$TB->Show();

modul.php
global $gender;
$this->LoadTemplate("modul.htm");
$this->Show();

The out put always show this error:
TinyButStrong Error in field [var.gender...] : the PHP global variable named 'gender' does not exist or is not set yet. This message can be cancelled using parameter 'noerr'.

anybody can help me ? :(
By: leo.b
Date: 2006-11-17
Time: 06:46

Re: getting mergeField to work?

Correction from my previous post:

main.htm
Helo, you are here ...
[onload;file=[var.file_include]]

left.htm
left content<br>
[var.file;script=submodul.php;subtpl]

userinfo.htm
Your gender is [var.gender]

my php script is....

modul.php
$file_include = "left.htm";
$TBS->LoadTemplate("main.htm");
$TBS->Show();

submodul.php
global $gender;
$gender = "M";
$this->LoadTemplate("userinfo.htm");
$this->Show();
------------------------------------
The out put always show this error:
TinyButStrong Error in field [var.gender...] : the PHP global variable named 'gender' does not exist or is not set yet. This message can be cancelled using parameter 'noerr'.

anybody can help me ? :(