Contentful logo

Contentful Community

Error when trying parsing rich-text field

Hello,
I’m a newbie and I’m doing some tests to see how Contentful works. I understood how to display the contents of text fields in my page, but I ran into a problem.
I am trying to display the content of a rich text field in my page but I have the following error:
Uncaught ArgumentCountError: Too few arguments to function Contentful \ RichText \ Parser :: __ construct (), 0 passed

My code :
<?php
require_once (‘vendor/autoload.php’);

$client = new \Contentful\Delivery\Client('XXXX', 'XXX', 'master');

$entries = $client->getEntries();
$entry = $client->getEntry('2ybs018raCs5Ssq2G1DqC8'); //a specific entry

$descript = $entry->getMyRichtextfiled();

$parser = new Contentful\RichText\Parser();
$node = $parser->parse($descript);

$renderer = new Contentful\RichText\Renderer();
$output = $renderer->render($node);

$level = $entry->getMyTextfiled1();
echo 'Titre : '.$entry->getMyTextfiled2(); 
echo '<br>Description : '.$output;
echo '<br>Type : '.$level;
?>

Can you help me ?
Thank’s

it’s working now !
No need to parse before displaying the content

<?php
require_once (‘vendor/autoload.php’);
$client = new \Contentful\Delivery\Client('XXXX', 'XXX', 'master');

$entries = $client->getEntries();
$entry = $client->getEntry('2ybs018raCs5Ssq2G1DqC8'); //a specific entry

$descript = $entry->getMyRichtextfiled();

$renderer = new Contentful\RichText\Renderer();
$output = $renderer->render($descript);

$level = $entry->getMyTextfiled1();
echo 'Titre : '.$entry->getMyTextfiled2(); 
echo '<br>Description : '.$output;
echo '<br>Type : '.$level;
?>
1 Like