Developer forum

Forum » Templates » If loop contains elements

If loop contains elements


Reply

Hoi,

 

I'd like to know if it's possible to test if me loop returns anything. i have a problem where i've made a custommodule that returns a collection of searchresults, which i list in my template with the following code:

 

---

 

<table>
 <tr>
  <td>Name</td>
  <td>Email</td>
  <td>Department</td>
  <td>Phone</td>
  <td>Country</td>
  <td>Local</td>
  <td>LogonName</td>
 </tr>
<!--@LoopStart(SearchResult)-->
 <tr>
  <td><!--@cm.Name--></td>
  <td><!--@cm.Email--></td>
  <td><!--@cm.Department--></td>
  <td><!--@cm.Phone--></td>
  <td><!--@cm.Country--></td>
  <td><!--@cm.Local--></td>
  <td><!--@cm.LogonName--></td>
 </tr>
<!--@LoopEnd(SearchResult)-->
</table>

 

---

 

The problem is that if my search returns 0 items, the ''table headers'' are rendered, which looks kinda stupid.

 

---

 

<table>
 <tr>
  <td>Name</td>
  <td>Email</td>
  <td>Department</td>
  <td>Phone</td>
  <td>Country</td>
  <td>Local</td>
  <td>LogonName</td>
 </tr>

</table>

 

---

 

So i wanna know if i can somehow test if my returns anything. I imagine something like this:

 

---

 

<!--If Defined(<!--SearchResult)-->

<table>
 <tr>
  <td>Name</td>
  <td>Email</td>
  <td>Department</td>
  <td>Phone</td>
  <td>Country</td>
  <td>Local</td>
  <td>LogonName</td>
 </tr>
<!--@LoopStart(SearchResult)-->
 <tr>
  <td><!--@cm.Name--></td>
  <td><!--@cm.Email--></td>
  <td><!--@cm.Department--></td>
  <td><!--@cm.Phone--></td>
  <td><!--@cm.Country--></td>
  <td><!--@cm.Local--></td>
  <td><!--@cm.LogonName--></td>
 </tr>
<!--@LoopEnd(SearchResult)-->
</table>

<!--EndIf Defined(<!--SearchResult)-->

 

---

 

Is it possible?

 

  /Martin


Replies

 
Nicolai Høeg Pedersen
Reply

Hi Martin

 

Take a look at http://template.dynamicweb.dk/TemplateTags/Dynamicweb-template-tags/General-tags/Loops.aspx - there you will find additional tags for use in loops to meet the situation you describe.

 

You must be logged in to post in the forum