|
40 | 40 | <p>You need Node.js version 4.4.7 or later installed to use the Contentstack JavaScript SDK.</p>
|
41 | 41 | <h3><a id="Setup_and_Installation_13"></a>Setup and Installation</h3>
|
42 | 42 | <h4><a id="For_JavaScript_Browser_15"></a>For JavaScript (Browser)</h4>
|
43 |
| - <p>To use the JavaScript SDK, download it from <a href="https://contentstack.com/docs/platforms/javascript-browser/javascript_sdk_latest">here</a> and include it in the <script> tag:</p> |
44 |
| - <pre><code><script type="text/javascript" src="/path/to/contentstack.min.js"></script>; |
| 43 | + <p>To use the JavaScript SDK, download it from <a href="https://www.contentstack.com/docs/platforms/javascript-browser/javascript_sdk_latest">here</a> and include it in the <script> tag:</p> |
| 44 | + <pre class="prettyprint"><code><script type="text/javascript" src="/path/to/contentstack.min.js"></script>; |
45 | 45 | </code></pre>
|
46 | 46 | <p>To initialize the SDK, you will need to specify the API Key, Access Token, and Environment Name of your stack.</p>
|
47 |
| - <pre><code>const Stack = Contentstack.Stack("api_key", "access_token", "environment_name"); |
| 47 | + <pre class="prettyprint"><code>const Stack = Contentstack.Stack("api_key", "access_token", "environment_name"); |
48 | 48 | </code></pre>
|
49 | 49 | <h4><a id="For_Nodejs_25"></a>For Node.js</h4>
|
50 |
| - <p>Node.js uses the Javascript SDK to create apps. To use the JavaScript SDK, download it from <a href="https://contentstack.com/docs/platforms/javascript-browser/javascript_sdk_latest">here</a>, OR install it via npm:</p> |
51 |
| - <pre><code>npm -i contentstack |
| 50 | + <p>Node.js uses the Javascript SDK to create apps. To use the JavaScript SDK, download it from <a href="https://www.contentstack.com/docs/platforms/javascript-browser/javascript_sdk_latest">here</a>, OR install it via npm:</p> |
| 51 | + <pre class="prettyprint"><code>npm -i contentstack |
52 | 52 | </code></pre>
|
53 | 53 | <p>To import the SDK in your project, use the following command:</p>
|
54 |
| - <pre><code>import contentstack from ‘contentstack’ |
| 54 | + <pre class="prettyprint"><code>import contentstack from ‘contentstack’ |
55 | 55 | </code></pre>
|
56 | 56 | <p>To initialize the SDK, you will need to specify the API Key, Access Token, and Environment Name of your stack.</p>
|
57 |
| - <pre><code>const Stack = Contentstack.Stack("api_key","access_token","environment_name"); |
| 57 | + <pre class="prettyprint"><code>const Stack = Contentstack.Stack("api_key","access_token","environment_name"); |
58 | 58 | </code></pre>
|
59 | 59 | <h4><a id="For_React_Native_39"></a>For React Native</h4>
|
60 |
| - <p>React Native uses the Javascript SDK to create apps. To use the JavaScript SDK, download it from <a href="https://contentstack.com/docs/platforms/javascript-browser/javascript_sdk_latest">here</a>, OR install ist via npm:</p> |
61 |
| - <pre><code>npm -i contentstack |
| 60 | + <p>React Native uses the Javascript SDK to create apps. To use the JavaScript SDK, download it from <a href="https://www.contentstack.com/docs/platforms/javascript-browser/javascript_sdk_latest">here</a>, OR install ist via npm:</p> |
| 61 | + <pre class="prettyprint"><code>npm -i contentstack |
62 | 62 | </code></pre>
|
63 | 63 | <p>To import the SDK in your project, use the following command:</p>
|
64 |
| - <pre><code>import contentstack from `contentstack/react-native` |
| 64 | + <pre class="prettyprint" class="prettyprint"><code>import contentstack from `contentstack/react-native` |
65 | 65 | </code></pre>
|
66 | 66 | <p>To initialize the SDK, you will need to specify the API Key, Access Token, and Environment Name of your stack.</p>
|
67 |
| - <pre><code>const Stack = Contentstack.Stack("api_key", "access_token", "environment_name"); |
| 67 | + <pre class="prettyprint"><code>const Stack = Contentstack.Stack("api_key", "access_token", "environment_name"); |
68 | 68 | </code></pre>
|
69 | 69 | <h3><a id="Key_Concepts_for_using_Contentstack_54"></a>Key Concepts for using Contentstack</h3>
|
70 | 70 | <h4><a id="Stack_56"></a>Stack</h4>
|
|
80 | 80 | <h3><a id="Contentstack_JavaScript_SDK_5minute_Quickstart_78"></a>Contentstack JavaScript SDK: 5-minute Quickstart</h3>
|
81 | 81 | <h4><a id="Initializing_your_SDK_80"></a>Initializing your SDK</h4>
|
82 | 82 | <p>You will need to specify the API key, Access token, and Environment Name of your stack to initialize the SDK:</p>
|
83 |
| - <pre><code>const Stack = Contentstack.Stack("api_key", "access_token", "environment_name"); |
| 83 | + <pre class="prettyprint"><code>const Stack = Contentstack.Stack("api_key", "access_token", "environment_name"); |
84 | 84 | </code></pre>
|
85 | 85 | <p>Once you have initialized the SDK, you can start getting content in your app.</p>
|
86 | 86 | <h4><a id="Querying_content_from_your_stack_90"></a>Querying content from your stack</h4>
|
87 | 87 | <p>To get a single entry, you need to specify the content type as well as the ID of the entry.</p>
|
88 |
| - <pre><code>const Query = Stack.ContentType('blog').Entry("blt123something"); |
| 88 | + <pre class="prettyprint"><code>const Query = Stack.ContentType('blog').Entry("blt123something"); |
89 | 89 |
|
90 | 90 | Query.fetch()
|
91 | 91 | .then(function success(entry) {
|
|
96 | 96 | });
|
97 | 97 | </code></pre>
|
98 | 98 | <p>To retrieve multiple entries of a content type, you need to specify the content type uid. You can also specify search parameters to filter results.</p>
|
99 |
| - <pre><code>const Query = Stack.ContentType('blog').Query(); |
| 99 | + <pre class="prettyprint"><code>const Query = Stack.ContentType('blog').Query(); |
100 | 100 |
|
101 | 101 | Query
|
102 | 102 | .where("title", "welcome")
|
|
117 | 117 | <p>You can set a cache policy on a stack and/or query object.</p>
|
118 | 118 | <h5><a id="Setting_a_cache_policy_on_a_stack_127"></a>Setting a cache policy on a stack</h5>
|
119 | 119 | <p>This option allows you to globalize a cache policy. This means the cache policy you set will be applied to all the query objects of the stack.</p>
|
120 |
| - <pre><code>//Setting a cache policy on a stack |
| 120 | + <pre class="prettyprint"><code>//Setting a cache policy on a stack |
121 | 121 | Stack.setCachePolicy(Contentstack.CachePolicy.NETWORK_ELSE_CACHE)
|
122 | 122 | </code></pre>
|
123 | 123 | <h5><a id="Setting_a_cache_policy_on_a_query_object_134"></a>Setting a cache policy on a query object</h5>
|
124 | 124 | <p>This option allows you to set/override a cache policy on a specific query object.</p>
|
125 |
| - <pre><code>// setting a cache policy on a queryobject |
| 125 | + <pre class="prettyprint"><code>// setting a cache policy on a queryobject |
126 | 126 | Query.setCachePolicy(Contentstack.CachePolicy.CACHE_THEN_NETWORK)
|
127 | 127 | </code></pre>
|
128 | 128 | <h3><a id="Advanced_Queries_141"></a>Advanced Queries</h3>
|
129 | 129 | <p>You can query for content types, entries, assets and more using our JavaScript API Reference.</p>
|
130 |
| - <p><a href="https://contentstack.com/docs/platforms/javascript-browser/api-reference">JavaScript API Reference Doc</a></p> |
| 130 | + <p><a href="https://www.contentstack.com/docs/platforms/javascript-browser/api-reference/">JavaScript API Reference Doc</a></p> |
131 | 131 | <h3><a id="Working_with_Images_147"></a>Working with Images</h3>
|
132 | 132 | <p>We have introduced Image Delivery APIs that let you retrieve images and then manipulate and optimize them for your digital properties. It lets you perform a host of other actions such as crop, trim, resize, rotate, overlay, and so on.</p>
|
133 | 133 | <p>For example, if you want to crop an image (with width as 300 and height as 400), you simply need to append query parameters at the end of the image URL, such as, <a href="https://images.contentstack.io/v3/assets/blteae40eb499811073/bltc5064f36b5855343/59e0c41ac0eddd140d5a8e3e/download?crop=300,400">https://images.contentstack.io/v3/assets/blteae40eb499811073/bltc5064f36b5855343/59e0c41ac0eddd140d5a8e3e/download?crop=300,400</a>. There are several more parameters that you can use for your images.</p>
|
|
136 | 136 | <h3><a id="Helpful_Links_157"></a>Helpful Links</h3>
|
137 | 137 | <ul>
|
138 | 138 | <li><a href="https://www.contentstack.com">Contentstack Website</a></li>
|
139 |
| - <li><a href="https://contentstack.com/docs">Official Documentation</a></li> |
140 |
| - <li><a href="https://contentstack.com/docs/apis/content-delivery-api/">Content Delivery API Docs</a></li> |
| 139 | + <li><a href="https://www.contentstack.com/docs">Official Documentation</a></li> |
| 140 | + <li><a href="https://www.contentstack.com/docs/apis/content-delivery-api/">Content Delivery API Docs</a></li> |
141 | 141 | </ul>
|
142 | 142 | <h3><a id="The_MIT_License_MIT_163"></a>The MIT License (MIT)</h3>
|
143 | 143 | <p>Copyright © 2012-2017 <a href="https://www.built.io/">Built.io</a>. All Rights Reserved</p>
|
|
0 commit comments