Skip to content

Instantly share code, notes, and snippets.

@acobster
Created April 24, 2019 19:05
Show Gist options
  • Save acobster/021da616f55c4fa1f49c94e57cf3f0ba to your computer and use it in GitHub Desktop.
Save acobster/021da616f55c4fa1f49c94e57cf3f0ba to your computer and use it in GitHub Desktop.
ACF Content Sections demo code
<?php
/**
* Author: Coby Tamayo
*/
use MyProject\Post\Page;
$page = new Page();
// Get common/site-wide data
$data = $site->get_context_with_post($page);
// Get the raw content_layouts data, formatted and filtered
$data['content_layouts'] = array_map(function(array $section) : array {
if ($section['pattern'] !== 'signup-form') {
unset($section['signup_form']);
}
if ($section['pattern'] !== 'accordion') {
unset($section['accordion']);
}
return $section;
}, $page->get_field('content_layouts') ?: []);
// Render the default view
Timber::render( 'page-content-layouts.twig'], $data );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment