新建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('DrupalmymoduleFormSearchForm');
    return [
      '#theme' => 'mycustomtemplate',
      '#search_form' => $search_form,
      '#cache' => ['contexts' => ['url.path', 'url.query_args']]
    ];

  }
{% block content %}
  {{ content }}
{% endblock %}
原文地址:https://www.cnblogs.com/qinqiu/p/8617955.html