<p>There’s no need to go through <code>getContent()</code> to access your field values; you can access them directly from the GlobalSetModel:</p>

<pre class="lang-php prettyprint-override"><code>'transformer' =&gt; function(GlobalSetModel $siteSettings) {
    return [
        'defaultTitle' =&gt; $siteSettings-&gt;defaultTitle,
        'defaultDescription' =&gt; $siteSettings-&gt;defaultDescription
    ];
},
</code></pre>

CC BY-SA 3.0
2016-03-07T16:26:32.633Z
That's what I was initially expecting, however when I try to access the field value as an attribute of $siteSettings, no values are being returned. Are there any gotchas I may be missing on the setup of the globals?
Coppa
CC BY-SA 3.0
2016-03-07T17:15:54.010Z
@Coppa Are `defaultTitle` and `defaultDescription` just regular Plain Text fields, or something else?
Brandon Kelly
CC BY-SA 3.0
2016-03-07T18:36:27.793Z
Ahh, great call. They're rich text fields (I changed the name of these fields for display on SE). I just tested a plain text field, and that let me access the value as you described. I was able to get the value of the rich text field using getParsedContent(). Thanks for the quick help!
Coppa
CC BY-SA 3.0
2016-03-07T11:27:30.190Z
2016-03-07T11:27:30.190Z
Brandon Kelly
<p>I'm pulling data from a Global Set using the <a href="https://github.com/pixelandtonic/ElementAPI" rel="nofollow">Element API plugin</a> and am wondering if there's a cleaner way to write the transformer function? </p>

<p>My <code>craft/config/elementapi.php</code> file looks like this:</p>

<pre><code>&lt;?php
namespace Craft;

return [
    'endpoints' =&gt; [
        'api/settings' =&gt; [
            'elementType' =&gt; 'GlobalSet',
            'criteria' =&gt; ['handle' =&gt; 'siteSettings'],
            'first' =&gt; true,
            'transformer' =&gt; function(GlobalSetModel $siteSettings) {
                return [
                    'defaultTitle' =&gt; $siteSettings-&gt;getContent()['defaultTitle'],
                    'defaultDescription' =&gt; $siteSettings-&gt;getContent()['defaultDescription']
                ];
            },
        ],
    ]
];
</code></pre>

<p>Thanks in advance!</p>

<globals><plugin-elementapi>
How to get field values from Global Set using Element API plugin?
# How to get field values from Global Set using Element API plugin?

(Asked by: username_0 on 2016-03-07)

I'm pulling data from a Global Set using the Element API plugin and am wondering if there's a cleaner way to write the transformer function? 
My craft/config/elementapi.php file looks like this:
 [
        'api/settings' => [
            'elementType' => 'GlobalSet',
            'criteria' => ['handle' => 'siteSettings'],
            'first' => true,
            'transformer' => function(GlobalSetModel $siteSettings) {
                return [
                    'defaultTitle' => $siteSettings->getContent()['defaultTitle'],
                    'defaultDescription' => $siteSettings->getContent()['defaultDescription']
                ];
            },
        ],
    ]
];

Thanks in advance!

**Tags:** globals, plugin-elementapi

---

## 1 answers

### Answer by username_1 on 2016-03-07. Score: 3 | Accepted answer

There’s no need to go through getContent() to access your field values; you can access them directly from the GlobalSetModel:
'transformer' => function(GlobalSetModel $siteSettings) {
    return [
        'defaultTitle' => $siteSettings->defaultTitle,
        'defaultDescription' => $siteSettings->defaultDescription
    ];
},

> **Comments:**
> **username_0**: That's what I was initially expecting, however when I try to access the field value as an attribute of $siteSettings, no values are being returned. Are there any gotchas I may be missing on the setup of the globals?  
> **username_1**: @Coppa Are `defaultTitle` and `defaultDescription` just regular Plain Text fields, or something else?  
> **username_0**: Ahh, great call. They're rich text fields (I changed the name of these fields for display on SE). I just tested a plain text field, and that let me access the value as you described. I was able to get the value of the rich text field using getParsedContent(). Thanks for the quick help!  

---

