You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+27-44Lines changed: 27 additions & 44 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -55,15 +55,16 @@ In order to pass the data correctly, you must pass `spike-contentful` an object,
55
55
56
56
Once included, it will expose a `contentful` local to your markup (`.sgr`, `.html`, etc...) files, which you can use to iterate through your content types. Based on the example above, the `posts` content type will be accessible through `contentful.posts`, as such:
57
57
58
-
59
58
```jade
60
59
// a template file
61
60
ul
62
61
each(loop='post of contentful.posts')
63
62
li {{ JSON.stringify(post) }}
64
63
```
64
+
65
65
For the sugar-free
66
-
```html
66
+
67
+
```html
67
68
<ul>
68
69
<eachloop="post of contentful.blog">
69
70
<li>{{ JSON.stringify(post) }}</li>
@@ -118,7 +119,7 @@ new Contentful({
118
119
119
120
### Transforms
120
121
121
-
Contentful returns a lot of associated data and, as a result, we include a way to clean it up. You also have the ability to pass your own custom `transform` option to each content type allowing you to transform the data however you like before it's sent to your views.
122
+
Contentful returns a lot of associated data and, as a result, we give you the ability to pass your own custom `transform` option to each content type allowing you to transform the data however you like before it's sent to your views.
122
123
123
124
```js
124
125
newContentful({
@@ -129,7 +130,7 @@ new Contentful({
129
130
{
130
131
name:'posts',
131
132
id:'633fTeiMaxxxxxxxxx',
132
-
transform:(post)=> {
133
+
transform:post=> {
133
134
// do your transformation here...
134
135
return post
135
136
}
@@ -138,30 +139,6 @@ new Contentful({
138
139
})
139
140
```
140
141
141
-
This plugin ships with a default transform function that will run some basic cleanup. However, be warned that the transform will enter an infinite loop and crash if there are circular references within the data, which is not an uncommon occurance, so please be very careful utilizing this transform. To enable our default transform, you can pass `true` as such:
142
-
143
-
```js
144
-
newContentful({
145
-
addDataTo: locals,
146
-
accessToken:'xxx',
147
-
spaceId:'xxx',
148
-
contentTypes: [
149
-
{
150
-
name:'posts',
151
-
id:'633fTeiMaxxxxxxxxx',
152
-
transform:true
153
-
}
154
-
]
155
-
})
156
-
```
157
-
158
-
If you'd like to use our default transform outside of the library, this is also available as an export. For example, you could include it and use it with client-side JS responses.
159
-
160
-
```js
161
-
constContentful=require('spike-contentful')
162
-
console.log(Contentful.transform)
163
-
```
164
-
165
142
### Templates
166
143
167
144
Using the template option allows you to write objects returned from Contentful to single page templates. For example, if you are trying to render a blog as static, you might want each post returned from the API to be rendered as a single page by itself.
0 commit comments