新建block+cache

https://drupal.stackexchange.com/questions/223376/what-is-the-correct-way-to-set-cache-contexts-on-custom-blocks
---------

public function build() {

    $search_form = \Drupal::formBuilder()->getForm('Drupal\mymodule\Form\SearchForm');
    return [
      '#theme' => 'mycustomtemplate',
      '#search_form' => $search_form,
      '#cache' => ['contexts' => ['url.path', 'url.query_args']]
    ];

  }
{% block content %}
  {{ content }}
{% endblock %}
posted @ 2018-03-21 16:39  qqisnow2021  阅读(85)  评论(0编辑  收藏  举报