1

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

2

Rather than calling getRawContent(), just explicitly cast your Rich Text field data into a string:

'summary' => ($entry->summary ? (string) $entry->summary : false),

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.