infinum / eightshift-frontend-libs

Frontend library that exposes custom scripts and styles for modern WordPress projects
https://eightshift.com
MIT License
71 stars 12 forks source link

[FEATURE] Create helper that can load reusable block in the template without the need to write large iterations of the code #459

Open iruzevic opened 3 years ago

iruzevic commented 3 years ago

This is the code example:

$commonContent = \get_field(ThemeOptions::FIELD_ARTICLE_COMMON_BLOCKS_KEY, 'option');

    // Load custom page set in theme options for listing intro.
    if ($commonContent) {
        $blocks = parse_blocks(get_the_content(null, null, $commonContent));

        foreach ($blocks as $block) {
            echo \apply_filters('the_content', \render_block($block)); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
        }
    }
DjidjaleskaSandra commented 6 months ago

In the theme options, it is necessary to have a dropdown list with templates, and accordingly, to select a template and which reusable block would be used in it? Or you have a different idea of how the templates and helper function could be connected?

iruzevic commented 6 months ago

helper is a helper no mater where the data is coming from it should be agnostic and you should pass the content via function arg