# CASE: use persisted to hide parts of a loop

**URL:** <https://community.silverfin.com/t/case-use-persisted-to-hide-parts-of-a-loop/1413>\
**Category:** Cases\
**Tags:** iterations, fori\_loop, methods, use\_case\
**Created:** [February 28, 2019, 8:48am UTC](https://community.silverfin.com/t/case-use-persisted-to-hide-parts-of-a-loop/1413 "2019-02-28T08:48:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sven](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/sven/32/1495_2.png) [@sven](https://community.silverfin.com/u/sven)\
**Post date:** [February 28, 2019, 8:48am UTC](https://community.silverfin.com/t/case-use-persisted-to-hide-parts-of-a-loop/1413/1 "2019-02-28T08:48:32Z")

</div>

There might be some cases into where your fori-loop creates a whole range of inputs that need to be done, like below:

 ![46](https://canada1.discourse-cdn.com/flex030/uploads/getsilverfin/original/1X/af9d86c111e3261bd68ffa6366b55ffcf3194889.png)

If you are like me, you’ll find the extra loop with all of its fields a little bit too much. I want to make the template a little less busy, and put extra emphasis that the first input is always needed to be filled in too.

By using the **persisted** method, I could make my template that way, that only the first field is visible. And only when information is filled in there, will it show all other fields, like this:

 ![08](https://canada1.discourse-cdn.com/flex030/uploads/getsilverfin/original/1X/c2b99251740021f91cb115db5399726aa606898c.png)

If nothing is filled, you’ll only see this:

 ![37](https://canada1.discourse-cdn.com/flex030/uploads/getsilverfin/original/1X/4262f86b96874182f624010178676a17b5b754b2.png)

As you can see, only one field is shown, and as a user you have no other option to fill it in.

You can make this work by using a `persisted` statement for all other fields, like this:

```auto
<table class="usr-width-100{% ic %} usr-bordered{% endic %}">
  <thead>
    <tr>
      <th class="usr-width-20 usr-line-bottom"><b>Name</b></th>
      <th class="usr-width-20 usr-line-bottom"></th>
      <th class="usr-line-bottom"></th>
    </tr>
  </thead>
  <tbody>
    {% fori comp in custom.companies %}
      <tr>
        <td>{% input comp.name %}</td>
        <td></td>
        <td></td>
      </tr>
      {% if comp.persisted %} {% comment %}all other fields will be shown depending on which the loop "exists" or not, and that is defined in the first input{% endcomment %}
      <tr>
        <td></td>
        <td>VAT number</td>
        <td>{% input comp.vat_nbr placeholder:"VAT nbr." %}</td>
      </tr>
      <tr>
        <td></td>
        <td>Street</td>
        <td>{% input comp.street placeholder:"Street" %}</td>
      </tr>
      <tr>
        <td></td>
        <td>Number</td>
        <td>{% input comp.nbr placeholder:"Number" %}</td>
      </tr>
      <tr>
        <td></td>
        <td>Postal code</td>
        <td>{% input comp.postal_code placeholder:"Postal code" %} </td>
      </tr>
      <tr>
        <td></td>
        <td>City</td>
        <td>{% input comp.city placeholder:"City" %}</td>
      </tr>
      <tr>
        <td></td>
        <td>Country</td>
        <td>{% input comp.country placeholder:"Country" %}</td>
      </tr>
      {% endif %}
    {% endfori %}
  </tbody>
</table>

```

Actually, the `persisted` reads the same as if the loop exists or not. There are other ways to do this as well (checking on the input of the first object to see if it’s empty), but this is shorter though

Here’s another case as well:

> [@CASE: create result tag in each loop](https://community.silverfin.com/t/case-create-result-tag-in-each-loop/1200):
>
> Let’s say we import certain data from a client, and we want to display each value of a certain column in a report template for instance: I’ll need to create a result-tag for each loop where data has been inputted. We can do this with the capture-method and the name of this can be used as a result-tag. Here’s the code: \<table class="usr-width-100"\> \<thead\> \<tr\> \<th class="usr-width-30 usr-line-bottom"\>\<b\>{% t "Kind" %}\</b\>\</th\> \<th class="usr-width-20 usr-line-bottom"\>\<…

_This case has been updated on 03/10/2022 to include HTML tables._
