Hi I'm trying to display the last links on the home page using a template and I was wanting to create a table where the links to be displayed are displayed one per row.
Using this global (found on the forum and modified a bit):
sub {
# Displays the newest links on the home page.
# Get the link information
my ($output,$sth,$link);
my $search_db = $DB->table('Links');
$search_db->select_options ('ORDER BY Add_Date DESC Limit 5');
$sth = $search_db->select (
# This only show links considered as new in the database
#{ isNew => 'Yes'},
{ isValidated => 'Yes'});
while (my $link = $sth->fetchrow_hashref()) {
# Get the links category information
my $catdb = $DB->table('CatLinks', 'Category');
my $catsth = $catdb->select ({ 'LinkID' => $link->{ID} }, ["Full_Name"]);
# This is the normal line
$link->{category} = $catsth->fetchrow_array;
$output .= Links::SiteHTML::display ('lastlinks', $link);
}
return $output;
}
I have a template called lastlinks that corresponds to a row and I have to create the table structure in home.html since the loop effect takes place through the sub.
In my home.html template I'll have :
<table border="0" cellpadding="3" cellspacing="0">
<tr>
<th><strong>Title</strong></th>
<th><strong>Editor</strong></th>
<th><strong>Category</strong></th></tr>
<%last_links%>
</table>
and the lastlinks.html template has this :
<tr><td><a href="<%db_cgi_url%>/detail_page.cgi?ID=<%ID%>"><%Title%></a></td>
<td><%Contact_Name%></td>
<td><%category%></td>
</tr>
I'd like to be able to create a loop in the lastlinks.html template so that I can just call the sub and that the lastlinks.html template has the whole structure with a loop in it. For example :
<table border="0" cellpadding="3" cellspacing="0">
<tr>
<th><strong>Title</strong></th>
<th><strong>Editor</strong></th>
<th><strong>Category</strong></th></tr>
<%loop links_loop%>
<tr><td><a href="<%db_cgi_url%>/detail_page.cgi?ID=<%ID%>"><%Title%></a></td>
<td><%Contact_Name%></td>
<td><%category%></td>
</tr>
<%endloop%>
</table>
I'm guessing I need to change the end of my sub to :
while ($link = $sth->fetchrow_hashref) {
push @links, $link;
}
return {LinksLoop=>\@output};
}
But I don't get where I tell the sub to use my lastlinks.html template to format the data...
Can I do this :
@output .= Links::SiteHTML::display ('lastsites', $link);
}
return {LinksLoop=>\@output};
}
If anyone someone could point me in the right direction
Thanks, John
Significant Media
Using this global (found on the forum and modified a bit):
sub {
# Displays the newest links on the home page.
# Get the link information
my ($output,$sth,$link);
my $search_db = $DB->table('Links');
$search_db->select_options ('ORDER BY Add_Date DESC Limit 5');
$sth = $search_db->select (
# This only show links considered as new in the database
#{ isNew => 'Yes'},
{ isValidated => 'Yes'});
while (my $link = $sth->fetchrow_hashref()) {
# Get the links category information
my $catdb = $DB->table('CatLinks', 'Category');
my $catsth = $catdb->select ({ 'LinkID' => $link->{ID} }, ["Full_Name"]);
# This is the normal line
$link->{category} = $catsth->fetchrow_array;
$output .= Links::SiteHTML::display ('lastlinks', $link);
}
return $output;
}
I have a template called lastlinks that corresponds to a row and I have to create the table structure in home.html since the loop effect takes place through the sub.
In my home.html template I'll have :
<table border="0" cellpadding="3" cellspacing="0">
<tr>
<th><strong>Title</strong></th>
<th><strong>Editor</strong></th>
<th><strong>Category</strong></th></tr>
<%last_links%>
</table>
and the lastlinks.html template has this :
<tr><td><a href="<%db_cgi_url%>/detail_page.cgi?ID=<%ID%>"><%Title%></a></td>
<td><%Contact_Name%></td>
<td><%category%></td>
</tr>
I'd like to be able to create a loop in the lastlinks.html template so that I can just call the sub and that the lastlinks.html template has the whole structure with a loop in it. For example :
<table border="0" cellpadding="3" cellspacing="0">
<tr>
<th><strong>Title</strong></th>
<th><strong>Editor</strong></th>
<th><strong>Category</strong></th></tr>
<%loop links_loop%>
<tr><td><a href="<%db_cgi_url%>/detail_page.cgi?ID=<%ID%>"><%Title%></a></td>
<td><%Contact_Name%></td>
<td><%category%></td>
</tr>
<%endloop%>
</table>
I'm guessing I need to change the end of my sub to :
while ($link = $sth->fetchrow_hashref) {
push @links, $link;
}
return {LinksLoop=>\@output};
}
But I don't get where I tell the sub to use my lastlinks.html template to format the data...
Can I do this :
@output .= Links::SiteHTML::display ('lastsites', $link);
}
return {LinksLoop=>\@output};
}
If anyone someone could point me in the right direction
Thanks, John
Significant Media