51 Posts
alanski
10 years ago
Topic

When using a file field as a repeatable field for content I am accessing in custom templates like:

        <?php
        $CountDocs = count($cck->get('file_list')->value);
        if ($CountDocs > 0 ):?>
        <ul class="list-unstyled">
            <?php foreach ($cck->get('file_list')->value as $gx):

The problem with file fileds is that the object exists when the document doesn't! So you end up with unwanted html around empty fields

I have worked around with below inside the loop
 if(strlen($gx['document']->link) > 0 ):

But this is not what i want - I want to count the files that exist in the array

Is this possible? How?

Get a VIP membership
4229 Posts
Kadministrator
10 years ago
1
Level 1

Instead of using count you could do a loop

$count = 0;

foreach ($cck->get('file_list')->value as $c)

{
    if(isset($gx['document']->link) && !empty($gx['document']->link)) 

     {

        $count++;

     }
}
51 Posts
alanski
10 years ago
0
Level 2

Thx Klas

Was trying to avoid two loops but i guess I can do it twice to avoid outputting unecessary html around existing file lists.

Many thanks

Get a VIP membership