Skip to content

Commit

Permalink
this helper will get reusable blocks content and render it
Browse files Browse the repository at this point in the history
  • Loading branch information
DjidjaleskaSandra committed May 14, 2024
1 parent 6424603 commit 630ab76
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Helpers/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ class Helpers
*/
use DeprecatedTrait;

/**
* Deprecated trait.
*/
use ReusableBlockTrait;

/**
* Get all project paths allowed to be used in the different render methods.
*
Expand Down
39 changes: 39 additions & 0 deletions src/Helpers/ReusableBlockTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

/**
* Helpers for reusable blocks.
*
* @package EightshiftLibs\Helpers
*/

declare(strict_types=1);

namespace EightshiftLibs\Helpers;

/**
* Trait ReusableBlockTrait helper.
*/
trait ReusableBlockTrait
{
/**
* Render reusable blocks content.
*
* This helper will get reusable blocks content and render it.
*
* @param int $commonContent ID of the reusable block content to render.
*
* @return string Rendered content.
*/
public static function renderReusableBlock(int $commonContent): string
{
$blocks = \parse_blocks(\get_the_content(null, false, $commonContent));

$renderedContent = '';

foreach ($blocks as $block) {
$renderedContent .= \apply_filters('the_content', \render_block($block));
}

return $renderedContent;
}
}

0 comments on commit 630ab76

Please sign in to comment.