forked from noblestudios/expressionengine-json-encode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusage.php
26 lines (17 loc) · 971 Bytes
/
usage.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
This plugin encapsulates PHP's json_encode function.
http://php.net/manual/en/function.json-encode.php
This plugin is useful when making JSON feed templates in EE.
Let's say we are making a feed that contains the 10 most recent blog posts. Our template would look like:
------------------------------------------------
{
"posts": [
{exp:channel:entries channel="blog" status="open" dynamic="no" limit="10" orderby="date" sort="desc" show_future_entries="no" }
{ "title": {exp:json_encode}{title}{/exp:json_encode}, "summary": {exp:json_encode}{summary}{/exp:json_encode}, "page_url": "{page_url}" }{if count<absolute_results}, {/if}
{/exp:channel:entries}
]
}
------------------------------------------------
Optionally, one may set the options parameter of json_encode as follows:
------------------------------------------------
{exp:json_encode options="JSON_UNESCAPED_UNICODE"}{title}{/exp:json_encode}
------------------------------------------------