# Get value from select field that's in a structure field

**URL:** <https://forum.getkirby.com/t/get-value-from-select-field-thats-in-a-structure-field/3059>\
**Category:** Questions\
**Tags:** v2\
**Created:** [January 15, 2016, 5:33pm UTC](https://forum.getkirby.com/t/get-value-from-select-field-thats-in-a-structure-field/3059 "2016-01-15T17:33:29Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![thewebprojects](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/thewebprojects/32/10107_2.png) [@thewebprojects](https://forum.getkirby.com/u/thewebprojects)\
**Post date:** [January 15, 2016, 5:33pm UTC](https://forum.getkirby.com/t/get-value-from-select-field-thats-in-a-structure-field/3059/1 "2016-01-15T17:33:29Z")

</div>

Okay. I give up. How do i get the value from a select field that’s in a structure field. Consider the following blueprint. Notice that my ‘social\_icon’ select field lists the images on the page.

```
  social:
    label: Social Channels
    type: structure
    style: table
    entry: >
      {{social_name}}
    fields:
      social_name:
        label: Name
        type: text
      social_icon
        label: Icon (SVG)
        type: select
        options: images
      social_url:
        label: URL
        type: text

```

I used a foreach loop and iterated through the “rows”. this allows me to easily get the text field values, but i’m struggling with the select value - maybe because i’m not sure how Kirby is outputting that value. Any insight would be appreciated.

---

<div class="post-metadata">

**Author:** ![thguenther](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/thguenther/32/16708_2.png) [@thguenther](https://forum.getkirby.com/u/thguenther)\
**Post date:** [January 15, 2016, 5:51pm UTC](https://forum.getkirby.com/t/get-value-from-select-field-thats-in-a-structure-field/3059/2 "2016-01-15T17:51:51Z")

</div>

Hey there,

it’s fairly easy to get a value of a specific field in a structure. But I think you already did this correctly by iterating through the fields as you mentioned. The select field with “images” as options simply outputs the **filename** of the selected image. So you will have to search the file in the current page.

```
<?php
    foreach($page->social()->toStructure() as $social):
?>
    <a href="<?= $social->social_url() ?>">
        <span class="name"><?= $social->social_name() ?></span>
        <img src="<?= $page->image($social->social_icon())->url() ?>"/>
    </a>
<?php
    endforeach;
?>

```

It’s untested but it should work.

Cheers,  
Thomas

---

<div class="post-metadata">

**Author:** ![thewebprojects](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/thewebprojects/32/10107_2.png) [@thewebprojects](https://forum.getkirby.com/u/thewebprojects)\
**Post date:** [January 15, 2016, 6:04pm UTC](https://forum.getkirby.com/t/get-value-from-select-field-thats-in-a-structure-field/3059/3 "2016-01-15T18:04:38Z")

</div>

Thanks for the quick response. That doesn’t work for me. There’s one more item worth mentioning; these fields are being set in the site blueprint. The following code echos each value except that blasted select field value.

```
$rows = $site->social()->toStructure();
        if(count($rows)):
        foreach($rows as $row):
            echo '<p>';
            echo 'social_url: ' . $row->social_url() . '<br/>';
            echo 'social_name: ' . $row->social_name() . '<br/>';
            echo 'social_icon: ' . $page->image($row->social_icon())->url();
            echo '</p>';
        endforeach;
        endif;
```

---

<div class="post-metadata">

**Author:** ![thguenther](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/thguenther/32/16708_2.png) [@thguenther](https://forum.getkirby.com/u/thguenther)\
**Post date:** [January 15, 2016, 6:07pm UTC](https://forum.getkirby.com/t/get-value-from-select-field-thats-in-a-structure-field/3059/4 "2016-01-15T18:07:22Z")

</div>

You write

```
$site->social()->toStructure()

```

instead of

```
$page->social()->toStructure()

```

So does that mean the “social” structure is in the site settings? If so, then you will have to change the social\_icon echo accordingly:

```
echo 'social_icon: ' . $site->image($row->social_icon())->url();
```

---

<div class="post-metadata">

**Author:** ![thewebprojects](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/thewebprojects/32/10107_2.png) [@thewebprojects](https://forum.getkirby.com/u/thewebprojects)\
**Post date:** [January 15, 2016, 6:11pm UTC](https://forum.getkirby.com/t/get-value-from-select-field-thats-in-a-structure-field/3059/5 "2016-01-15T18:11:26Z")

</div>

I figured that and did try $site instead of $page. For example, the following geneates all values except that select value.

```
$rows = $site->social()->toStructure();
if(count($rows)):
foreach($rows as $row):
    echo '<p>';
    echo 'social_url: ' . $row->social_url() . '<br/>';
    echo 'social_name: ' . $row->social_name() . '<br/>';
    echo 'social_icon: ' . $site->image($row->social_icon())->url();
    echo '</p>';
endforeach;
endif;
```

---

<div class="post-metadata">

**Author:** ![thguenther](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/thguenther/32/16708_2.png) [@thguenther](https://forum.getkirby.com/u/thguenther)\
**Post date:** [January 15, 2016, 6:18pm UTC](https://forum.getkirby.com/t/get-value-from-select-field-thats-in-a-structure-field/3059/6 "2016-01-15T18:18:48Z")

</div>

I quickly reconstructed your setting and files on a local, empty install.

Your blueprint is missing a “:” after “social\_icon” 🙂

---

<div class="post-metadata">

**Author:** ![thewebprojects](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/thewebprojects/32/10107_2.png) [@thewebprojects](https://forum.getkirby.com/u/thewebprojects)\
**Post date:** [January 15, 2016, 6:29pm UTC](https://forum.getkirby.com/t/get-value-from-select-field-thats-in-a-structure-field/3059/7 "2016-01-15T18:29:35Z")

</div>

Oh dear. Yep. That’ll jack things up. It works now. I appreciate your time. Thank you.

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 5:00pm UTC](https://forum.getkirby.com/t/get-value-from-select-field-thats-in-a-structure-field/3059/8 "2025-02-06T17:00:26Z")

</div>


