Components, our flexible content system.
composer require cuberis/wp-componify
.
- Setup new template parts in
/templates/components/
to match against ACF Flexible Content layout slugs. - Instantiate new Componify class in your page template.
- Sit back and enjoy!
<?php while (have_posts()) : the_post(); ?>
<article>
<header>
<h1 class="entry-title"><?php the_title(); ?></h1>
</header>
<div class="entry-content">
<?php
$components = new Componify();
$components->render();
?>
</div>
</article>
<?php endwhile; ?>
prefix
(default: null) – Retrieve a prefixed set of component fields.
/**
* Example for modifying component wrapper attributes.
*
* @param array $attrs
* @param string $slug
* @return $attrs
*/
function cuberis_filter_component_html_attributes($attrs, $slug) {
// Add a class modifier to just the text component.
if ($slug === 'text') {
$attrs['class'] .= ' component--example-modifier';
}
// Add a new attribute to all components.
$attrs['data-id'] = uniqid();
return $attrs;
}
add_filter('cuberis_set_component_html_attributes', 'cuberis_filter_component_html_attributes', 10, 2);