Skip to content

Commit

Permalink
Merge pull request #25 from badabingbreda/classnames
Browse files Browse the repository at this point in the history
- Added note in docs/installation.md to warn developers to use filena…
  • Loading branch information
palmiak authored Jun 24, 2020
2 parents e4ac4ea + 8bab4a3 commit a7af9cc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docs/example.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
SupportsMultiple: false
#}
<blockquote data-{{ block.id }}>
<blockquote class="{{ block.classes }}" data-{{ block.id }}>
<p>{{ fields.testimonial }}</p>
<cite>
<span>{{ fields.author }}</span>
Expand Down
4 changes: 4 additions & 0 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ composer require "palmiak/timber-acf-wp-blocks"

Next you can create your blocks in your theme in **views/blocks** folder (you can change it with a filter).

> **Note**: filenames should only contain lowercase alphanumeric characters and dashes, and must begin with a letter.


When you have your blocks ready the only thing left it to create a New group in ACF and select your block in **Show this field group if** selector.
16 changes: 8 additions & 8 deletions timber-acf-wp-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,19 +191,19 @@ function () {
*/
function timber_blocks_callback( $block, $content = '', $is_preview = false, $post_id = 0 ) {
// Set up the slug to be useful.
$context = Timber::get_context();
$context = \Timber::get_context();
$slug = str_replace( 'acf/', '', $block['name'] );

$context['block'] = $block;
$context['post_id'] = $post_id;
$context['slug'] = $slug;
$context['is_preview'] = $is_preview;
$context['fields'] = get_fields();
$classes = array(
$slug,
isset( $block['className'] ) ? $block['className'] : null,
$is_preview ? 'is-preview' : null,
'align' . $context['block']['align'],
$classes = array_merge(
array( $slug ),
isset( $block['className'] ) ? array( $block['className'] ) : array(),
$is_preview ? array( 'is-preview' ) : array(),
array( 'align' . $context['block']['align'] ),
);

$context['classes'] = implode( ' ', $classes );
Expand All @@ -221,7 +221,7 @@ function timber_blocks_callback( $block, $content = '', $is_preview = false, $po

$paths = timber_acf_path_render( $slug, $is_preview, $is_example );

Timber::render( $paths, $context );
\Timber::render( $paths, $context );
}

/**
Expand Down Expand Up @@ -258,7 +258,7 @@ function timber_blocks_subdirectories( $directories ) {
$ret = array();

foreach ( $directories as $base_directory ) {
$template_directory = new \RecursiveDirectoryIterator( \locate_template( $base_directory ), FilesystemIterator::KEY_AS_PATHNAME | FilesystemIterator::CURRENT_AS_SELF );
$template_directory = new \RecursiveDirectoryIterator( \locate_template( $base_directory ), \FilesystemIterator::KEY_AS_PATHNAME | \FilesystemIterator::CURRENT_AS_SELF );

if ( $template_directory ) {
foreach ( $template_directory as $directory ) {
Expand Down

0 comments on commit a7af9cc

Please sign in to comment.