Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Catalyst: Users

Template render in parts

 

 

Catalyst users RSS feed   Index | Next | Previous | View Threaded


venish at deeproot

Sep 2, 2009, 10:10 PM

Post #1 of 2 (791 views)
Permalink
Template render in parts

Hi all,


I am trying to display the LDAP search entries using 'callback' option in
the search method.
I have been successful in handling the callback option and got 'one by one
result'.
But I found a problem in displaying the search entries in a Template using
the catalyst framework.

I want to display LDAP search entries in TT. But I want to show the search
entries directly.
When I receive the first search result, I want to show it (that result) in
TT and the back-end process should automatically search the second entry
and so on.
Similarly, when I get the second search result, I want to show that
result in TT and similarly the back-end process should automatically
search the next entry and so on.

It means when I get the search results directly, it should be ideally
displayed in the TT without waiting for all the search results.
For this mechanism, I used the Net::LDAP search method. Search method
provides callback option to return one by one search results.
For the template, I used Template::Alloy module. I used both modules (i.e.
Net::LDAP and Template::Alloy) in my CGI application. Both work perfectly.

Now I want to use this mechanism in Catalyst applications as well. I
searched and designed the following module
Catalyst::Helper::View::TT::Alloy. I believe it should work perfectly in
place of the Template::Alloy module. Could you please give your
comments/insights on this as I'm not completely sure about it.

It would also be of immense help if you could refer me some other module
which would/could work in place of the Template::Alloy module perfectly in
the Catalyst framework for different applications.


I would be grateful if any one help me how to access this module with
Catalyst framework.

Looking forward to a prompt response.

--
Venish Khant
www.deeproot.co.in


_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


venish at deeproot

Sep 8, 2009, 12:24 AM

Post #2 of 2 (651 views)
Permalink
Re: Template render in parts [In reply to]

Here I given example which is working in CGI application.

==============Callback.cgi===============
#!/usr/bin/perl
use Template::Alloy;
use Net::LDAP;

my $tr = Template::Alloy->new(

EXPOSE_BLOCKS => 1,

INCLUDE_PATH => "./",

);

print "Content-type: text/html\n\n";
$tr->process("userlist.tt/header", {title => 'MyStore', date =>
scalar(localtime)});


sub search_result {
my ( $mesg, $entry) = @_;

if ( !defined($entry) ) {
if ($mesg->count == 0) {
return;
}
}

my $dn = $entry->dn; # Obtain DN of this entry
my $cn = $entry->get_value( "cn", asref => 1 );
my $mail = $entry->get_value( "mail", asref => 1 );
my $uid = $entry->get_value( "uid", asref => 1 );
my $vars = {
dn => "$dn",
cn => "@$cn",
mail => "@$mail",
uid => "@$uid",
};
$tr->process("userlist.tt/UserList", $vars);
$mesg->pop_entry;

} # End of callback subroutine

$ldap = Net::LDAP->new('localhost') or die "$@";
$ldap->bind(
dn => "uid=admin,ou=people,dc=example,dc=co,dc=in",
password => "admin"
);

$mesg = $ldap->search (
base => "dc=example,dc=co,dc=in",
scope => "sub",
filter => "uid=*",
attrs => ["dn", "cn", "mail", "uid"],
callback => \&search_result,
);

if ( $mesg->code ) {
$errstr = $mesg->code;
print "Error code: $errstr\n";
}

$tr->process("userlist.tt/footer", \%row);

=========userlist.tt========
[% BLOCK header ~%]
<html>
<head>
<title>my site - [% title %]</title>
</head>
<body>
<h4>The date is [% date %]</h4>
<table border=1>
<tr>
<th>DN</th>
<th>CN</th>
<th>Mail</th>
<th>UID</th>
</tr>
[% END %]
[% BLOCK UserList ~%]
<tr>
<td>[% dn %]</td>
<td>[% cn %]</td>
<td>[% mail %]</td>
<td>[% uid %]</td>
</tr>
[% END %]
[% BLOCK footer ~%]
</table>
</body>
</html>
[% END %]



> Hi all,
>
>
> I am trying to display the LDAP search entries using 'callback' option in
> the search method.
> I have been successful in handling the callback option and got 'one by
> one
> result'.
> But I found a problem in displaying the search entries in a Template
> using
> the catalyst framework.
>
> I want to display LDAP search entries in TT. But I want to show the
> search
> entries directly.
> When I receive the first search result, I want to show it (that
> result) in
> TT and the back-end process should automatically search the second entry
> and so on.
> Similarly, when I get the second search result, I want to show that
> result in TT and similarly the back-end process should automatically
> search the next entry and so on.
>
> It means when I get the search results directly, it should be ideally
> displayed in the TT without waiting for all the search results.
> For this mechanism, I used the Net::LDAP search method. Search method
> provides callback option to return one by one search results.
> For the template, I used Template::Alloy module. I used both modules
> (i.e.
> Net::LDAP and Template::Alloy) in my CGI application. Both work
> perfectly.
>
> Now I want to use this mechanism in Catalyst applications as well. I
> searched and designed the following module
> Catalyst::Helper::View::TT::Alloy. I believe it should work perfectly in
> place of the Template::Alloy module. Could you please give your
> comments/insights on this as I'm not completely sure about it.
>
> It would also be of immense help if you could refer me some other module
> which would/could work in place of the Template::Alloy module
> perfectly in
> the Catalyst framework for different applications.
>
>
> I would be grateful if any one help me how to access this module with
> Catalyst framework.
>
> Looking forward to a prompt response.
>


--
Venish Khant
www.deeproot.co.in


_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/

Catalyst users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.