Categories > TinyButStrong general >

conditional subtemplates

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: juglesh
Date: 2006-03-22
Time: 01:26

conditional subtemplates

Ok, I dont get it, sorry.

here is my php:
$TBS->LoadTemplate('t5.htm') ;
$formgood=0;
if ($form->validate()) {
$formgood=1;
  $process =  $form->process('process_data', false);
}
$TBS->Show() ;

main template t5.htm:
<html>
<head>
[var.newr.javascript;htmlconv=no;protect=no]
</head><body>
[onload_1;file='t5form.php';when [var.formgood]=0;subtpl]
[onload_1;file='t5process.php';when [var.formgood]=1;subtpl]

t5form.php:
<form [var.newr.attributes;htmlconv=no] >
[var.newr.sections.0.elements.0.html;htmlconv=no]<br>
[var.newr.sections.0.elements.1.html;htmlconv=no]<br>
[var.newr.sections.0.elements.2.html;htmlconv=no]<br>
[var.newr.sections.0.elements.3.html;htmlconv=no]<br>
</form>

t5process.php:
[var.process]  <br>

I think you can see that I would like to use one subtemplate to show the form, and another to show the results.  I named the tpls .php, but just out of habit.

I get a 'Can't merge [var.process] ' error the first time the page is run, but I shouldnt see that at all untill after I run the form.

Upon submit the form, I get the process I expect, but I still get the form.

confused,
thanks for your time,
juglesh
By: Skrol29
Date: 2006-03-22
Time: 01:50

Re: conditional subtemplates

Hello juglesh,

Parameter 'when' is for block only. Fields need parameter 'if' instead.
And you've defined only fields (no parameter block used).
I suggest the following:
<html>
<head>
[var.newr.javascript;htmlconv=no;protect=no]
</head><body>
[onload;file=[var.formgood;if [val]=0;then 't5form.php';else 't5process.php']
</body>
</html>
By: juglesh
Date: 2006-03-22
Time: 13:26

Re: conditional subtemplates

Hello, and Thanks,

That code you gave apparently missing an end bracket (cant find end of tag).  So I put a ] at the end.

then I get
'Can't merge [var.formgood] because there is no PHP global variable named 'formgood'
Which is mysterious, cuz I am able to show that variable using a simple [var.formgood] in the same tpl.

Also, on the same page:
'(Parameter 'file'): Field [onload] : unable to read the file '[var.formgood;if =0;then 't5form.php';else 't5process.php']'

--
juglesh
By: Skrol29
Date: 2006-03-22
Time: 13:32

Re: conditional subtemplates

Yes , this is because youe templae use a [onload] automatic field wich is processed when you call LoadTemplate(). But LoadTemplate() is called before $formgood is set, that why TBS cannot merge it.

Just Move the line:
  $TBS->LoadTemplate('t5.htm') ;
after $formgood is set.
By: juglesh
Date: 2006-03-22
Time: 13:43

Re: conditional subtemplates


bingo!
Thanks much!

juglesh