Skip to content
This repository was archived by the owner on Feb 17, 2022. It is now read-only.

7.x 2.x easy block

Andy Truong edited this page Feb 18, 2014 · 3 revisions

Easy Block — [7.x-2.x]

Blocks can be defined in yaml config style:

# %module_name/config/blocks.yml
blocks:
  # Simple string definition
  hello_string:
    info: 'Hello String'
    subject: 'Hello String'
    cache: DRUPAL_CACHE_PER_ROLE
    content: 'Hello Andy Truong'

  # Support template rendering
  hello_template:
    info: 'Hello template'
    subject: 'Hello template'
    cache: DRUPAL_CACHE_PER_PAGE
    content:
      template: '@module_name/templates/block/hello_template.html.twig'
      variables: {name: 'Andy Truong'}

  # Support asset attachment
  hello_template_string:
    info: 'Hello Template String'
    subject: 'Hello Template String'
    content:
      template_string: "{{ 'slider_front' | drupalView }}"
      attached:
        css: ['%theme/css/slider.css']
        js: ['//cdnjs.cloudflare.com/ajax/libs/jquery.cycle/3.03/jquery.cycle.all.min.js']

  # Support dynamic arguments
  hello_dynamic_arguments:
    info: 'Hello dynamic argument'
    subject: 'Hello dynamic argument'
    content:
      content: '{% if node and node.status %} {{ node.title }} {% endif %}'
      variables:
        node: menu_get_object
        foo: ['Foo_Class', 'barMethod']
        srv: 'service_name:method'

Clone this wiki locally