Re: Question with regard to "append" to a form with TT
David Turland <[email protected]> Fri, 26 Feb 2016 20:15:13 +0000
| Newsgroups | gmane.comp.lang.perl.modules.template-toolkit |
|---|---|
| Message-ID | <[email protected]> |
Hi
I am guessing you are assembling a string from repeated calls to process on=
e or more templates, cherry-picking sections from each?
Maybe something like this:
( note that $page is passed in by reference )
#=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
#!/usr/bin/perl
use Template;
my $template =3D <<'END';
[% IF set_first_part %]
first_part_of_form
[% ELSIF set_second_part %]
second_part_of_form
[% END %]
END
my $tt =3D Template->new();
my $page;
$tt->process( \$template, { set_first_part =3D> 1,}, \$page ) or print $tt=
->error, "\n";
$page .=3D "\n--- half way ---\n";
$tt->process( \$template, { set_second_part =3D> 1,}, \$page ) or print $tt=
->error, "\n";
print $page;
#=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
yields:
first_part_of_form
--- half way ---
second_part_of_form
#=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
If not, then maybe some more info would help..
Regards,
David
On 26/02/16 18:31, Norris, Joseph wrote:
>
> Hello all,
>
> Did quite a bit of work with TT some years ago =96 just coming into a pro=
ject where it will be ideal.
>
> Here is my issue:
>
> I am converting a bunch of html embedded scripts into TT based scripts an=
d I have a situation where ( for lack of better words ) I =
> must =93append=94 parts of forms to other parts =96 so I have a the follo=
wing mockup
>
> first_part_of_form
>
> on condtion =96 keep first_part_of_form and append
>
> second_part_of_form
>
> I have tried setting if conditions in my perl script and do the process t=
o a variable but when I do the following:
>
> $form->{set_first_part} =3D true
>
> and then in the form I have [% IF set_first_part =3D=3D =91true=92 %]
>
> first_part_of_form
>
> [% END %]
>
> And then set it to false =96 as expected I do not get the first_part_of_f=
orm - I need to keep this intact and then append =
> second_part_of_form
>
> Maybe I am over-thinking this but I would like to get to as close as I ca=
n to a single html file to handle what I am doing.
>
> I would appreciate any suggestion of how I might go about this =96 maybe =
there is something in TT that I have not even considered
>
> Thanks for your help.
>
> *Joseph Norris *social-icons_green-linkedin.png <https://www.linkedin.com=
/company/pacific-metrics>**social-icons_green-twitter.png =
> <https://twitter.com/PacificMetrics>
>
> **Software Applications Engineer
>
> *PACIFIC METRICS*****
>
> 1 Lower Ragsdale Dr #150*| *Monterey, CA 93940
>
> *T*_623-203-8866_
>
> *E*jnorris-4Bh+/[email protected] <mailto:jnorris-4Bh+/[email protected]>*| W*www=
.pacificmetrics.com <http://www.pacificmetrics.com/>__
>
> *email-sig-logo.jpg*
>
>
>
> _______________________________________________
> templates mailing list
> [email protected]
> http://mail.template-toolkit.org/mailman/listinfo/templates