cuberis/wp-componify

Components, our flexible content system.

0.1.0 2019-03-18 19:33 UTC

This package is not auto-updated.

Last update: 2024-05-12 03:38:35 UTC


README

Latest Version on Packagist

Components, our flexible content system.

Installing

composer require cuberis/wp-componify.

Setup & Examples

  1. Setup new template parts in /templates/components/ to match against ACF Flexible Content layout slugs.
  2. Instantiate new Componify class in your page template.
  3. 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; ?>

Arguments

  • prefix (default: null) – Retrieve a prefixed set of component fields.

Filters

cuberis_set_component_html_attributes

/**
 * 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);