Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6107487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:11:37+00:00 2026-05-23T14:11:37+00:00

foreach $result (keys %{$results_ref}){ $source = $results_ref->{$result}->{abs_path}; $source =~ s#/home/##; print <div><img src=\$source\ /></div>;

  • 0
foreach $result (keys %{$results_ref}){
    $source = $results_ref->{$result}->{abs_path};
    $source =~ s#/home/##;
    print "<div><img src=\"$source\" /></div>";
}

It seems HTML:Template only support basic syntax. How can I do logic like above with it?

UPDATE

An arrayref to hash is not always enough ,consider the following example:

print $hash{LEFT};
foreach $i ($hash{START}..$hash{END}){
    if($pager == $i){
        print "<span>$i<span>";
    }
    else {
        print "<span><a href=\"/index.pl?page=$i\">$i</a></span>";
    }

How would you do it with arrayref to hash?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:11:38+00:00Added an answer on May 23, 2026 at 2:11 pm

    If I understand your question correctly I think you are looking for the TMPL_LOOP tag.

    Build an array of hashes, and pass that as a variable to param() call. Then use TMPL_LOOP to build what you were doing in the foreach.

     my $sources_loop = [];
     foreach $result (keys %$results_ref) {
        $source = $results_ref->{$result}->{abs_path};
        $source =~ s#/home/##;
        push(@$sources_loop, { source => $source });
     }
    
     $template->param(sourcesloop => $sources_loop);
    

    Then in the template:

     <!--TMPL_LOOP NAME="sourcesloop"-->
         <div><img src="<!--TMPL_VAR NAME="source"-->" /></div>
     <!--/TMPL_LOOP-->
    

    EDIT (response to Update):

    Again, if I understand correctly, then I would use different keys to drive the logic of the template loop. You can have TMPL_IF as part of TMPL_LOOP

    my $sources_loop = [];
    foreach $i ($hash{START}..$hash{END}){
        if($pager == $i){
             push(@$sources_loop, { lone => $i });
        }
        else {
            push(@$sources_loop, { linked => $i });
        }
    }
    
    $template->param(sourcesloop => $sourcesloop, hashleft => $hash{LEFT});
    

    Template:

     <!--TMPL_VAR NAME="hashleft"-->
     <!--TMPL_LOOP NAME="sourcesloop"-->
         <!--TMPL_IF NAME="lone"--><span><!--TMPL_VAR NAME="lone"-->"</span><!--/TMPL_IF-->
         <!--TMPL_IF NAME="linked"--><span><a href="/index.pl?page=<!--TMPL_VAR NAME="linked"-->"><!--TMPL_VAR NAME="linked"--></a></span><!--/TMPL_IF-->
     <!--/TMPL_LOOP-->
    

    EDIT: updated to include $hash{LEFT}

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

in code igniter you can type: $query = $this->db->query(YOUR QUERY); foreach ($query->result() as $row)
I have a very simple query $this->db->select('id, title'); $this->db->order_by('id', 'DESC'); $query = $this->db->get('journal'); foreach($query->result()
<c:set var=nameLookup value=${names} /> <c:forEach var=result items=${results}> <tr> <td>${result.uglyDisplayName}</td> <td>${result.phonenum}</td> </tr> </c:forEach> This is
I am looking for the equivalent of a foreach loop with keys in Actionscript.
Possible Duplicate: How does foreach work when looping through function results? If I have
I'd like to send an email for each row of a result set using
We have several different optimization algorithms that produce a different result for each run.
foreach ($_GET as $field => $label) { $datarray[]=$_GET[$field]; echo $_GET[$field]; echo <br>; } print_r($datarray);
foreach($arrayOne as $value){ do function } In the above example, I'd like to pass
foreach (var person in peopleList.Where(person => person.FirstName == Messi)) { selectPeople.Add(person); } I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.