I am trying to build out an api template inside our CMS to expose a particular channel as json. I'm going to call that channel "public." Here's the template that I have put together thus far:
[
{exp:channel:entries channel="public" dynamic="no"
limit="{segment_3}"
offset="{segment_4}"
orderby="{segment_5}"
}
{ "title" : "{title}", "source" : "{public_html}" }{if count < total_results},{/if}
{/exp:channel:entries}
]
There are two channel fields defined public_html
and public_css
that represent the stored contents of the content item. As is, it is delivering my data as text/html
and I am needing to switch it to application/json
to instruct the browser.
So, I tried adding
<?php header("Content-Type: application/json"); ?>
to the top of my template (moved it around and saw no changes), but it is still delivering text/html (verified through fiddler) In the long run, I can handle text/html in my service layer, but I would really prefer this to be done right.
How do I add the Content-Type: application/json
HTTP Header to the template that I provided?