Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-07T16:26:32.633Z
Answers.Text: 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?
Answers.UserDisplayName: Coppa
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-07T17:15:54.010Z
Answers.Text: @Coppa Are `defaultTitle` and `defaultDescription` just regular Plain Text fields, or something else?
Answers.UserDisplayName: Brandon Kelly
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-07T18:36:27.793Z
Answers.Text: 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!
Answers.UserDisplayName: Coppa
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-07T11:27:30.190Z
Answers.LastActivityDate: 2016-03-07T11:27:30.190Z
Answers.UserDisplayName: Brandon Kelly
Body: <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>
  
Tags: <globals><plugin-elementapi>
Title: How to get field values from Global Set using Element API plugin?
ThreadText: # 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](https://github.com/pixelandtonic/ElementAPI) and am wondering if there's a cleaner way to write the transformer function?
  
  My `craft/config/elementapi.php` file looks like this:
  
  ```
  <?php
  namespace Craft;
  
  return [
      'endpoints' => [
          '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:
  
  ```php
  '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**: @username_0 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!  
  
  ---
  
  