Wordpress Bundle
  • What is Wordpress Bundle?
  • Getting started
    • Installation
    • Wordpress
    • Router
    • Cron job
    • Templates
  • Reference
    • Argument resolver
    • Controller
      • AdminAction
      • BlogController
      • FrontAction
      • WordpressAction
    • Entity
      • Block
      • Blog
      • Comment
      • File
      • Image
      • Menu
      • MenuItem
      • Post
      • Term
      • User
    • Repository
      • CommentRepository
      • PostRepository
      • TermRepository
      • UserRepository
    • Service
      • PaginationService
      • BreacrumbService
  • Guides
    • Server requirements
    • Install plugins
    • Use Multisite
    • Gutenberg
    • WP Steroids plugin
      • Image options
      • Maintenance
      • Admin pages removal
      • WYSIWYG Editor
      • Feature Support
      • Multi-site configuration
      • Constants definition
      • ACF configuration
      • Menu
      • Custom Post type
      • Advanced permalink settings
      • Custom Taxonomy
      • Templates
      • Page states
      • External table viewer
      • Roles
      • Optimisations
      • Security
      • Search
    • Twig Cookbook
    • Inject variables in all templates
    • Internationalization
    • Extending Wordpress Bundle
    • Error pages
    • Site health
  • Integrations
    • Advanced Custom Fields
      • Install ACF PRO
  • Extras
    • Migrating from 1.x to 2.0
    • Roadmap
    • Changelog
    • Alternatives
Powered by GitBook
On this page
  • Declare blocks
  • Use blocks

Was this helpful?

  1. Guides

Gutenberg

From 2.0.3

PreviousUse MultisiteNextWP Steroids plugin

Last updated 1 year ago

Was this helpful?

Declare blocks

Edit config/packages/wordpress.yaml

  block:
    title-text:
      title: Title with text
      description: Title with text
      render_template: 'templates/block/acf/title-text.html.twig'
      category: 'layout'
      icon: 'editor-alignleft'
      preview_image: true

    title-text-image:
      title: Title with text and image
      description: Title with text and image
      render_template: 'templates/block/acf/title-text-image.html.twig'
      category: 'layout'
      icon: 'align-left'
      align_text: 'left'
      preview_image: true

To use block preview image feature, save block preview images as /uploads/blocks/{block-name}.png

Use blocks

Include blocks in template from loop

Please note that {{ post.content|raw }} will also display blocks html but for performance reasons, use post.blocks object

{# templates/page.html.twig #}

{% for block in post.blocks %}
    {% include 'block/'~block.name~'.html.twig' with { props: block.content } %}
{% endfor %}

Access block data and attributes

{# templates/block/acf/title-text-image.html.twig #}

<section class="o-title-text-image o-title-text-image--{{ block.align_text }}">
    <div class="container">

        <div class="o-title-text-image__content">
            <h2 class="o-title-text-image__title">{{ props.title }}</h2>
	    <div class="o-title-text-image__text">{{ props.text|raw }}</div>
	</div>
	{% if props.image|default %}
	    <div class="o-title-text-image__image">
	        {{ props.image|picture(585,356) }}
	    </div>
	{% endif %}
    </div>
</section>