# Get a structurefield content for a own field type

**URL:** <https://forum.getkirby.com/t/get-a-structurefield-content-for-a-own-field-type/11031>\
**Category:** Questions\
**Tags:** v2\
**Created:** [August 12, 2018, 11:37pm UTC](https://forum.getkirby.com/t/get-a-structurefield-content-for-a-own-field-type/11031 "2018-08-12T23:37:11Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![JanStieler](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/janstieler/32/15642_2.png) [@JanStieler](https://forum.getkirby.com/u/JanStieler)\
**Post date:** [August 12, 2018, 11:37pm UTC](https://forum.getkirby.com/t/get-a-structurefield-content-for-a-own-field-type/11031/1 "2018-08-12T23:37:11Z")

</div>

Hi,

I have a structurefield where a customer can generate discountcodes for a registerform for a conference.  
No I want to serve him a field where he can see a link where the discountcode is inside as a variable.

My problem now is how can I get a field from the structure I’m actual in it in the panel?

Best

---

<div class="post-metadata">

**Author:** ![bvdputte](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bvdputte/32/8179_2.png) [@bvdputte](https://forum.getkirby.com/u/bvdputte)\
**Post date:** [August 13, 2018, 6:26am UTC](https://forum.getkirby.com/t/get-a-structurefield-content-for-a-own-field-type/11031/2 "2018-08-13T06:26:40Z")

</div>

Maybe the [controlledlist plugin](https://github.com/rasteiner/controlledlist) is a good place to look in?

In short: this plugin fetches its “options” via a controller you create (so you can have whatever logic you want in it), and supplies it to another field (it extends the checkboxes, radio & select field are included).

---

<div class="post-metadata">

**Author:** ![JanStieler](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/janstieler/32/15642_2.png) [@JanStieler](https://forum.getkirby.com/u/JanStieler)\
**Post date:** [August 18, 2018, 4:00pm UTC](https://forum.getkirby.com/t/get-a-structurefield-content-for-a-own-field-type/11031/3 "2018-08-18T16:00:38Z")

</div>

HI,  
thanks for your reply.  
To get the content from a normal panelfield is not my problem. I need the content of a structurefield.  
I had also not an idea how my logic should look like to get the structure?  
I tried it with `$this`or `parentField()`but can’t see what in my pageobjekct can help me to identify in which structure I’m actually in it.

Actually with `$page->discounts()->toStructure()`I get all structure field contents but I don’t know in which I’m actually in it to use the right key?

```auto
Structure Object
(
    [0] => Structure Object
        (
            [hash_id] => Field Object
                (
                    [page] => validation-registration
                    [key] => hash_id
                    [value] => 3ddacdce632652fc3b2c06328cda47b8
                )

            [discountname] => Field Object
                (
                    [page] => validation-registration
                    [key] => discountname
                    [value] => Superstakeholder
                )

            [discount] => Field Object
                (
                    [page] => validation-registration
                    [key] => discount
                    [value] => 250.00
                )

            [discountend] => Field Object
                (
                    [page] => validation-registration
                    [key] => discountend
                    [value] => 2018-08-16
                )

            [discountid] => Field Object
                (
                    [page] => validation-registration
                    [key] => discountid
                    [value] => Superstakeholder-250
                )

        )

    [1] => Structure Object
        (
            [hash_id] => Field Object
                (
                    [page] => validation-registration
                    [key] => hash_id
                    [value] => 71a243d77a9b68fa068a6e97b2943134
                )

            [discountname] => Field Object
                (
                    [page] => validation-registration
                    [key] => discountname
                    [value] => Contentcreator
                )

            [discount] => Field Object
                (
                    [page] => validation-registration
                    [key] => discount
                    [value] => 200.00
                )

            [discountend] => Field Object
                (
                    [page] => validation-registration
                    [key] => discountend
                    [value] => 
                )

            [discountid] => Field Object
                (
                    [page] => validation-registration
                    [key] => discountid
                    [value] => contentcreator-200
                )

        )

)

```

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [August 18, 2018, 4:22pm UTC](https://forum.getkirby.com/t/get-a-structurefield-content-for-a-own-field-type/11031/4 "2018-08-18T16:22:11Z")

</div>

Maybe you can explain your use case a bit better, I have trouble understanding it.

Do you mean while the user is editing an item. inside the structure field you want to display the value of this. structure field. item in another field? And why?

Or something completely different?

---

<div class="post-metadata">

**Author:** ![JanStieler](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/janstieler/32/15642_2.png) [@JanStieler](https://forum.getkirby.com/u/JanStieler)\
**Post date:** [August 18, 2018, 4:39pm UTC](https://forum.getkirby.com/t/get-a-structurefield-content-for-a-own-field-type/11031/5 "2018-08-18T16:39:15Z")

</div>

Hi,

the basicfunction of the structurefield is to save discountcodes, for this I have five fields

- hash\_id ( actually not really used)
- discountid (the discountidentifier)
- discountname (the discountname)
- discount (the discountvalue)
- discountend (for timelimited discounts)

now I want to serve another field where the customer can directly see a link with the discountcode.  
And if he press the link he can write directly a mail to his customer with this link to use the discountcode.  
Also the return of the field should look like:  
`return '<a href="mailto:?body='. $page->url() . $page->hash_id() .'">'. $page->url() . $hash->hash_id() .'</a>';` (actually the php output is not right. pls. ignore).  
I know that I need javascript for the direct output, but after one save it should work I think. If I get the direct structurefield.

Cheers

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [August 18, 2018, 4:49pm UTC](https://forum.getkirby.com/t/get-a-structurefield-content-for-a-own-field-type/11031/6 "2018-08-18T16:49:27Z")

</div>

Well, an active item is opened in a modal, so you could use JavaScript to read the value of the desired field from the input field in the modal and then inject it into your custom field.

But I think I would handle this differently, somehow this sounds like a rather fragile solution. Maybe output the complete set somwhere with the links or insert an additional field into the structure with the link on page save, so when the user opens the item the. next time, he can click the click.

---

<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:26pm UTC](https://forum.getkirby.com/t/get-a-structurefield-content-for-a-own-field-type/11031/7 "2025-02-06T17:26:26Z")

</div>


