Answers.Body: <p>Rather than calling <code>getRawContent()</code>, just explicitly cast your Rich Text field data into a string:</p>
  
  <pre class="lang-php prettyprint-override"><code>'summary' =&gt; ($entry-&gt;summary ? (string) $entry-&gt;summary : false),
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-20T23:00:32.967Z
Answers.LastActivityDate: 2015-10-20T23:00:32.967Z
Answers.UserDisplayName: Brandon Kelly
Body: <p>I'm wanting to return HTML content via the ElementAPI. I seem to be able to do this with the following <code>elements.php</code>:</p>
  
  <pre><code>'endpoints' =&gt; [
      'api/trials.json' =&gt; [
          'elementType' =&gt; 'Entry',
          'criteria' =&gt; ['section' =&gt; 'trials'],
          'transformer' =&gt; function(EntryModel $entry) {
              return [
                  'summary' =&gt; ($entry-&gt;summary ? $entry-&gt;summary-&gt;getRawContent() : false),
                  ...
              ];
          },
      ]
  ]
  </code></pre>
  
  <p>It's just that the <code>getRawContent()</code> returns the following in the JSON:</p>
  
  <pre><code>"summary": "&lt;p&gt;&lt;img src=\"{asset:46:url}\"…
  </code></pre>
  
  <p>When I'm expecting:</p>
  
  <pre><code>"summary": "&lt;p&gt;&lt;img src=\"/images/myimage.png"…
  </code></pre>
  
  <p>Should I be using a different method to get to the content, or do I need to run the content through some kind of transformation?</p>
  
  <p>Thanks in advance,</p>
  
  <p>James</p>
  
Tags: <entrymodel><plugin-elementapi>
Title: How to get rendered image paths from the ElementAPI?
ThreadText: # How to get rendered image paths from the ElementAPI?
  
  (Asked by: username_0 on 2015-10-20)
  
  I'm wanting to return HTML content via the ElementAPI. I seem to be able to do this with the following `elements.php`:
  
  ```
  'endpoints' => [
      'api/trials.json' => [
          'elementType' => 'Entry',
          'criteria' => ['section' => 'trials'],
          'transformer' => function(EntryModel $entry) {
              return [
                  'summary' => ($entry->summary ? $entry->summary->getRawContent() : false),
                  ...
              ];
          },
      ]
  ]
  
  ```
  
  It's just that the `getRawContent()` returns the following in the JSON:
  
  ```
  "summary": "<p><img src=\"{asset:46:url}\"…
  
  ```
  
  When I'm expecting:
  
  ```
  "summary": "<p><img src=\"/images/myimage.png"…
  
  ```
  
  Should I be using a different method to get to the content, or do I need to run the content through some kind of transformation?
  
  Thanks in advance,
  
  James
  
  **Tags:** entrymodel, plugin-elementapi
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-10-20. Score: 2 | Accepted answer
  
  Rather than calling `getRawContent()`, just explicitly cast your Rich Text field data into a string:
  
  ```php
  'summary' => ($entry->summary ? (string) $entry->summary : false),
  
  ```
  
  
  ---
  
  