Skip to content

Commit a590a0a

Browse files
committed
docs: 📝 Readme file updated
1 parent 7c6554a commit a590a0a

2 files changed

Lines changed: 67 additions & 6 deletions

File tree

.talismanrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fileignoreconfig:
2+
- filename: README.md
3+
allowed_patterns: [API_KEY, DELIVERY_TOKEN, ENVIRONMENT, Contentstack::]

README.md

Lines changed: 64 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,33 @@ use Contentstack\Utils\Resource\RenderableInterface;
3636
use Contentstack\Utils\Resource\EmbeddedObject;
3737
use Contentstack\Utils\Model\Option;
3838
use Contentstack\Utils\Model\Metadata;
39-
use Contentstack\Utils\Enum\StyleType;
40-
41-
class CustomOption extends Option {
39+
use Contentstack\Utils\Enum\StyleType;
40+
use Contentstack\Utils\Enum\NodeType;
41+
use Contentstack\Utils\Enum\MarkType;
42+
43+
class CustomOption extends Option {
44+
function renderMark(MarkType $markType, string $text): string
45+
{
46+
switch ($markType)
47+
{
48+
case MarkType::get(MarkType::BOLD):
49+
return "<b>".$text."</b>";
50+
default:
51+
return parent::renderMark($markType, $text);
52+
}
53+
}
54+
function renderNode(NodeType $nodeType, object $node, string $innerHtml): string
55+
{
56+
switch ($nodeType)
57+
{
58+
case NodeType::get(NodeType::PARAGRAPH):
59+
return "<p class='class-id'>".$innerHtml."</p>";
60+
case NodeType::get(NodeType::HEADING_1):
61+
return "<h1 class='class-id'>".$innerHtml."</h1>";
62+
default:
63+
return parent::renderNode($nodeType, $node, $innerHtml);
64+
}
65+
}
4266
function renderOptions(array $embeddedObject, Metadata $metadata): string
4367
{
4468
switch ($metadata->getStyleType()) {
@@ -61,7 +85,7 @@ class CustomOption extends Option {
6185
return "<a href=".$metadata->getAttribute("href")->value
6286
.">".$metadata->getText()."</a>"
6387
}
64-
return $resultString;
88+
return parent::renderOptions($embeddedObject, $metadata);
6589
}
6690
}
6791
```
@@ -70,8 +94,9 @@ class CustomOption extends Option {
7094
Contentstack Utils SDK lets you interact with the Content Delivery APIs and retrieve embedded items from the RTE field of an entry.
7195
7296
### Fetch Embedded Item(s) from a Single Entry:
97+
#### Render HTML RTE Embedded object
7398
74-
To get an embedded item of a single entry, you need to provide the stack API key, environment name, delivery token, content type’s UID, and entry’s UID. Then, use the includeEmbeddedItems function as shown below:
99+
To get an embedded item of a single entry, you need to provide the stack API key, environment name, delivery token, content type’s UID, and entry’s UID. Then, use the `Contentstack::renderContent` function as shown below:
75100
76101
```php
77102
use Contentstack\Contentstack;
@@ -84,9 +109,27 @@ $render_rich_text = Contentstack::renderContent($entry['rte_field_uid'], new Opt
84109

85110
If you want to render embedded items using the CustomOption function, you can refer to the code below:
86111
```php
87-
$rendered_rich_text = Contentstack.render_content($entry['rte_field_uid'], new CustomOption($entry));
112+
$rendered_rich_text = Contentstack.renderContent($entry['rte_field_uid'], new CustomOption($entry));
113+
```
114+
#### Render Supercharged RTE contents
115+
To get a single entry, you need to provide the stack API key, environment name, delivery token, content type and entry UID. Then, use `Contentstack::jsonToHtml` function as shown below:
116+
117+
118+
```php
119+
use Contentstack\Contentstack;
120+
use Contentstack\Utils\Model\Option;
121+
122+
$stack = Contentstack::Stack('<API_KEY>', '<ENVIRONMENT_SPECIFIC_DELIVERY_TOKEN>', '<ENVIRONMENT>');
123+
$entry = $stack->ContentType('<CONTENT_TYPE_UID>')->Entry('<ENTRY_UID>')->includeEmbeddedItems()->toJSON()->fetch();
124+
$render_rich_text = Contentstack::jsonToHtml($entry['rte_field_uid'], new Option($entry));
125+
```
126+
127+
If you want to render embedded items using the CustomOption function, you can refer to the code below:
128+
```php
129+
$rendered_rich_text = Contentstack.jsonToHtml($entry['rte_field_uid'], new CustomOption($entry));
88130
```
89131
### Fetch Embedded Item(s) from Multiple Entries
132+
#### Render HTML RTE Embedded object
90133

91134
To get embedded items from multiple entries, you need to provide the stack API key, environment name, delivery token, and content type’s UID.
92135
```php
@@ -100,3 +143,18 @@ for($i = 0; $i < count($result[0]); $i++) {
100143
$render_rich_text = Contentstack::renderContent($entry['rich_text_content'], new Option($entry));
101144
}
102145
```
146+
147+
#### Render Supercharged RTE contents
148+
To get a single entry, you need to provide the stack API key, environment name, delivery token, content type UID. Then, use `Contentstack::jsonToHtml` function as shown below:
149+
150+
```php
151+
use Contentstack\Contentstack;
152+
use Contentstack\Utils\Model\Option;
153+
154+
$stack = Contentstack::Stack('<API_KEY>', '<ENVIRONMENT_SPECIFIC_DELIVERY_TOKEN>', '<ENVIRONMENT>');
155+
$result = $stack->ContentType('<CONTENT_TYPE_UID>')->Query()->toJSON()->includeEmbeddedItems()->find()
156+
for($i = 0; $i < count($result[0]); $i++) {
157+
$entry = $result[0][$i];
158+
$render_rich_text = Contentstack::jsonToHtml($entry['rich_text_content'], new Option($entry));
159+
}
160+
```

0 commit comments

Comments
 (0)