php 具有嵌入视图的自定义模块

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 具有嵌入视图的自定义模块相关的知识,希望对你有一定的参考价值。

# Custom Module with embeded view

Documentation on how to use a controller to embed a view in a custom module.

## Reference

[Render a Drupal 8 View programmatically (Render arrays FTW!)](https://www.computerminds.co.uk/articles/render-drupal-8-view-programmatically-render-arrays-ftw)
views_template.content:
  path: '/viewstemplate'
  defaults:
    _controller: '\Drupal\views_template\Controller\ViewsController::content'
    _title: 'Views Template Module'
  requirements:
    _permission: 'access content'
<?php

namespace Drupal\views_template\Controller;

use Drupal\Core\Controller\ControllerBase;

/**
 * Defines ViewsTest class.
 */
class ViewsController extends ControllerBase {

  /**
   * Display the markup.
   *
   * @return array
   *   Return markup array.
   */
  public function content() {

    return [
      '#type' => 'view',
      '#name' => 'view_testing',
      '#display_id' => 'embed_1',
    ];
  }
}

// '#type' => 'view' is the magic that lets Drupal's rendering system know that this array represents a view to render.
// '#name' is the machine name of the view you want to render.
// '#display_id' is the display ID within the view to render. You can find the machine name for this in /admin/structure/views/your_view under the Advanced grouping.
// '#arguments' is an optionally array of arguments to pass to the view.


以上是关于php 具有嵌入视图的自定义模块的主要内容,如果未能解决你的问题,请参考以下文章

Swift:嵌入在导航控制器中的视图之间的自定义segue

如何响应从 xib 加载的自定义视图中发生的操作?

以编程方式获取嵌入在 UIStackView 中的自定义 UIView

Drupal 视图模块卡在我的自定义主题上

如何继承具有 .xib 文件的自定义视图

具有不是 UITableViewController 的自定义主视图控制器的 UISplitViewController