Skip to content

Instantly share code, notes, and snippets.

@taotiwordpress
Created August 26, 2020 19:02
Show Gist options
  • Save taotiwordpress/6ce1f9239068b480056b37b2d9cf60b2 to your computer and use it in GitHub Desktop.
Save taotiwordpress/6ce1f9239068b480056b37b2d9cf60b2 to your computer and use it in GitHub Desktop.
[text-block] Page builder text block module #pagebuilder
<?php
namespace Modules;
use Timber;
### Example usage
// $args = [
// 'text_block' => get_sub_field('text_block'),
// ];
// $new_module = new TextBlock($args);
// $new_module->render();
class TextBlock {
protected $defaults;
protected $context;
public function __construct( $args=[] ){
$this->defaults = [
'text_block' => false,
'classes' => [
'l-module',
'l-container',
'textBlock',
]
];
extract(array_merge($this->defaults, $args));
$processed_content = do_shortcode( $text_block );
$this->context = Timber::get_context();
$this->context['content'] = $processed_content;
$this->context['classes'] = implode(' ', $classes);
}
public function render(){
Timber::render('textBlock.twig', $this->context);
}
}
.textBlock-content {
@include containerSmall();
.wp-caption {
font-size: .88em;
p {
margin-top: .66rem;
font-size: 1rem;
color: $color-gray;
}
}
}
{% block textBlock %}
<div class="{{ classes }}">
<div class="l-inner textBlock-inner">
{% if content %}
<div class="textBlock-content entry-content">{{ content }}</div>
{% endif %}
</div>
</div>
{% endblock %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment