Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Template::Toolkit - How do i access alias-based results?

by tangent (Priest)
on Jul 13, 2015 at 14:14 UTC ( #1134512=note: print w/replies, xml ) Need Help??


in reply to Template::Toolkit - How do i access alias-based results?

Add this to the top of your template:
[% USE Dumper %]
Then add the dump within the loop:
[% FOREACH user = query.execute( ) %] [% Dumper.dump( user ) %]

Replies are listed 'Best First'.
Re^2: Template::Toolkit - How do i access alias-based results?
by Yaerox (Scribe) on Jul 13, 2015 at 14:23 UTC
    Dump seems to work fine ...

    [% FOREACH user = query.execute() %] [% Dumper.dump( user ) %] <tr class="tbl_3_col_ia_tr1"> <td class="tbl_3_col_ia_td tbl_3_col_i +a_td_1 tbl_3_col_ia_text"> <span> [% user.vertragsnummer %] </span> </td> <td class="tbl_3_col_ia_td tbl_3_col_i +a_td_2 tbl_3_col_ia_text"> <span class="tbl_3_col_ia_span_mid +_l"> [% user.artikelnr %] </span> <span class="tbl_3_col_ia_span_mid +_r"> </span> </td> <td class="tbl_3_col_ia_td tbl_3_col_i +a_td_3 tbl_3_col_ia_text"> <span class=""> </span> </td> </tr> [% END %]

    Output (dump works fine, my output still is empty):
    $VAR1 = { 'DATUM' => '09-JUL-15', 'STATUS' => 'Eingelesen', 'NR' => '1 +1000530', 'NACHRICHT' => '528', 'aNR' => '8041094A' }; $VAR1 = { 'aNR +' => '8033010E', 'NR' => '11000527', 'STATUS' => 'Eingelesen', 'NACHR +ICHT' => '1559', 'DATUM' => '09-JUL-15' }; [...]

    Well, if I do user.SOMESTUFF and SOMESTUFF in Uppercase it works ...


    Update: okay, I'd like to try the same now by passing values to template. Would you be so kind and help me here too? So I know both ways to do this ...
    print "Content-type: text/html\n\n"; my $oTT = Template->new({ INCLUDE_PATH => '../templates', EVAL_PERL => 1, ABSOLUTE => 1, }) || die "$Template::ERROR\n"; #DB - Connect my $hDB = DBI->connect( "dbi:Oracle:xx", "xx", "xx", { AutoCommit => 0 + } ); my $hStatement = $hDB->prepare("MYSQL"); $hStatement->execute( ); while ( ( $iVertragsnummer, $sArtikelNr, $sVertragsStatus, $sVertragsD +atum, $iMsgID ) = $hStatement->fetchrow_array() ){ push (@aRows, ( $iVertragsnummer, $sArtikelNr, $sVertragsStatus, $s +VertragsDatum, $iMsgID )); } $hStatement->finish; $hDB->disconnect; my $sData = { 'result' => \@aRows }; $oTT->process("../templates/mytemplate.html", $sData) || die $oTT->err +or(), "\n";
    [% FOREACH line IN result %] [% Dumper.dump( line ) %] [% line.VERTRAGSNUMMER %] [% line.ARTIKELNR %] [% END %]
    I get the following output of my dump:
    $VAR1 = '11000530'; $VAR1 = '8041094A'; $VAR1 = 'Eingelesen'; [...]
    my line.vars are empty again. I think I'm doing something wrong with references in perl?
      I think I'm doing something wrong with references in perl?

      You're doing something wrong with @aRows alright - and the solution has already been given to you here

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1134512]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2017-12-16 21:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (459 votes). Check out past polls.

    Notices?