Skip to content

Commit 0afe285

Browse files
committed
📝 Readme update
- Added JsonToHtml Document
1 parent c25a62a commit 0afe285

1 file changed

Lines changed: 82 additions & 6 deletions

File tree

README.md

Lines changed: 82 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,31 @@ public class CustomRenderOption: Options
4747
{
4848
public CustomRenderOption(IEntryEmbedable entry) : base(entry)
4949
{
50-
}
50+
}
51+
public override string RenderMark(MarkType markType, string text)
52+
{
53+
switch (markType)
54+
{
55+
case MarkType.Bold:
56+
return $"<b>{text}</b>";
57+
default:
58+
return base.RenderMark(markType: markType, text: text);
59+
}
60+
}
61+
62+
public override string RenderNode(NodeType nodeType, Node node, NodeChildrenCallBack callBack)
63+
{
64+
switch (nodeType)
65+
{
66+
case NodeType.Paragraph:
67+
return $"<p class='class-id'>{callBack(node.children)}</p>";
68+
case NodeType.Heading_1:
69+
return "<h1 class='class-id'>{necallBackxt(node.children)}</h1>";
70+
default:
71+
return base.RenderNode(nodeType, node, callBack);
72+
}
73+
}
74+
5175
public override string RenderOption(IEmbeddedObject embeddedObject, Metadata metadata)
5276
{
5377
switch (metadata.StyleType)
@@ -127,15 +151,16 @@ CustomRenderOption defaultRender = new CustomRenderOption(entry);
127151
Contentstack Utils SDK lets you interact with the Content Delivery APIs and retrieve embedded items from the RTE field of an entry.
128152

129153
### Fetch Embedded Item(s) from a Single Entry
154+
#### Render HTML RTE Embedded object
130155

131-
To get an embedded item of a single entry, you need to provide the stack API key, environment name, delivery token, content type and entry UID:
156+
To get an embedded item of a single entry, you need to provide the stack API key, environment name, delivery token, content type and entry UID. Then, use the `ContentstackUtils.RenderContent` functions as shown below::
132157
```c#
133158
using Contentstack.Core; // ContentstackClient
134159
using Contentstack.Core.Models; // Stack, Query, Entry, Asset, ContentType, ContentstackCollection
135160
using Contentstack.Core.Configuration; // ContentstackOptions
136161
using Contentstack.Utils; // Utils.RenderContent
137162
Using Contentstack.Utils.Models; // Options, Metadata
138-
ContentstackClient client = new ContentstackClient("api_key", "delivery_token", "enviroment_name");
163+
ContentstackClient client = new ContentstackClient("api_key", "delivery_token", "environment_name");
139164

140165
client.ContentType("product").Entry("<entry_uid>");
141166
.includeEmbeddedItems()
@@ -149,17 +174,39 @@ client.ContentType("product").Entry("<entry_uid>");
149174
});
150175
```
151176

152-
### Fetch Embedded Item(s) from Multiple Entries
177+
#### Render Supercharged RTE contents
153178

154-
To get embedded items from multiple entries, you need to provide the stack API key, environment name, delivery token, content type UID. You can use the path variable in case the entries have multiple RTE fields.
179+
To get a single entry, you need to provide the stack API key, environment name, delivery token, content type and entry UID. Then, use `Utils.JsonToHtml` function as shown below:
180+
```c#
181+
using Contentstack.Core; // ContentstackClient
182+
using Contentstack.Core.Models; // Stack, Query, Entry, Asset, ContentType, ContentstackCollection
183+
using Contentstack.Core.Configuration; // ContentstackOptions
184+
using Contentstack.Utils; // Utils.RenderContent
185+
Using Contentstack.Utils.Models; // Options, Metadata
186+
ContentstackClient client = new ContentstackClient("api_key", "delivery_token", "environment_name");
187+
188+
client.ContentType("product").Entry("<entry_uid>");
189+
.includeEmbeddedItems()
190+
.Fetch<Product>().ContinueWith((response) => {
191+
if (!response.IsFaulted) {
192+
// To use the default render option:
193+
string result = Utils.JsonToHtml(response.result.rte, new Option(response.result));
194+
// To use the Custom render option:
195+
string result = Utils.JsonToHtml(response.result.rte, new CustomRenderOption(response.result));
196+
}
197+
});
198+
```
199+
### Fetch Embedded Item(s) from Multiple Entries
200+
#### Render HTML RTE Embedded object
201+
To get embedded items from multiple entries, you need to provide the stack API key, environment name, delivery token, content type UID. Then, use the `ContentstackUtils.RenderContent` functions as shown below:
155202
```c#
156203
using Contentstack.Core; // ContentstackClient
157204
using Contentstack.Core.Models; // Stack, Query, Entry, Asset, ContentType, ContentstackCollection
158205
using Contentstack.Core.Configuration; // ContentstackOptions
159206
using Contentstack.Utils; // Utils.RenderContent
160207
Using Contentstack.Utils.Models; // Options, Metadata
161208
162-
ContentstackClient client = new ContentstackClient("api_key", "delivery_token", "enviroment_name");
209+
ContentstackClient client = new ContentstackClient("api_key", "delivery_token", "environment_name");
163210

164211
client.ContentType("product").Query()
165212
.includeEmbeddedItems();
@@ -175,4 +222,33 @@ client.ContentType("product").Query()
175222
}
176223
}
177224
});
225+
```
226+
227+
228+
#### Render Supercharged RTE contents
229+
To get embedded items from multiple entries, you need to provide the stack API key, environment name, delivery token, content type UID. Then, use `Utils.jsonToHtml` function as shown below:
230+
231+
```c#
232+
using Contentstack.Core; // ContentstackClient
233+
using Contentstack.Core.Models; // Stack, Query, Entry, Asset, ContentType, ContentstackCollection
234+
using Contentstack.Core.Configuration; // ContentstackOptions
235+
using Contentstack.Utils; // Utils.RenderContent
236+
Using Contentstack.Utils.Models; // Options, Metadata
237+
238+
ContentstackClient client = new ContentstackClient("api_key", "delivery_token", "environment_name");
239+
240+
client.ContentType("product").Query()
241+
.includeEmbeddedItems();
242+
.Find<Product>().ContinueWith((t) => {
243+
if (!t.IsFaulted) {
244+
ContentstackCollection<Product> result = t.Result;
245+
foreach (var product in result.Items)
246+
{
247+
// To use the default render option
248+
string result = Utils.JsonToHtml(product.rte, new Option(product));
249+
// To use the Custom render option
250+
string result = Utils.JsonToHtml(product.rte, new CustomRenderOption(product));
251+
}
252+
}
253+
});
178254
```

0 commit comments

Comments
 (0)