Slot

Slot提供了一种向特定页面特定区域注入内容的能力。那些特定区域,我们称之为插槽(Slot)。

使用

定义Slot

例如在course/show.html.twig页面中,我们定义了:

  1. <div class="course-sidebar">
  2. {{ slot('course.show.sidebar', {'course':course}) }}
  3. ...
  4. </div>

注入

1.添加YourPlugin/Resources/config/slots.yml

  1. - name: course.show.sidebar
  2. class: YourPlugin\Slot\CourseShowSidebarSlot
  3. priority: 10

2.添加YourPlugin/Slot/CourseShowSidebarSlot.php

  1. <?php
  2. namespace YourPlugin\Slot;
  3. use Codeages\PluginBundle\System\Slot\SlotInjection;
  4. class CourseShowSidebarSlot extends SlotInjection
  5. {
  6. public function inject()
  7. {
  8. // ...
  9. return $this->container->get('twig')->render(
  10. 'YourPlugin:Slot:course-show-sidebar-slot.html.twig'
  11. );
  12. }
  13. }
  14. ?>

Slot列表

后续会补充。