Hi!
Is there a way to render a single paragraph item programmatically?

Comments

arrubiu’s picture

Category: Feature request » Support request
jeroen.b’s picture

Yes:

$entities = entity_load('paragraphs_item', array($pagraphs_item_id));
$paragraphs_render = entity_view($entities, 'full');

Ofcourse you have to provide $pagraphs_item_id yourself.
The result in $paragraphs_render is a render array, which you can render with drupal_render($paragraphs_render);

arrubiu’s picture

thanks a lot!
A little correction: the right way to get the array is:

$paragraphs_render = entity_view('paragraphs_item', $entities, 'full');

:)

jeroen.b’s picture

Status: Active » Closed (fixed)

Ah, sorry, I tried to do it without testing the code ;)

rahul_sankrit’s picture

After node load:

[revision_uid] => 1
    [field_push_package_content] => Array
        (
            [und] => Array
                (
                    [0] => Array
                        (
                            [value] => 35
                            [revision_id] => 449
                        )

                    [1] => Array
                        (
                            [value] => 37
                            [revision_id] => 450
                        )

                )

        )

Worked for me:

$entities = entity_load('paragraphs_item', array('35'));
$paragraphs_render = entity_view('paragraphs_item', $entities, 'full');
print drupal_render($paragraphs_render);

Note: 35 and 37= pagraphs_item_id.

Thanks

opgobee’s picture

Thank you rahul_sankrit for the worked out example #5! Was helpful.