Linked Questions

2 votes
3 answers
15k views

Render a custom block programmatically [duplicate]

How do I render a custom block type (block_content) programmatically with a specific display view?
David DIVERRES's user avatar
7 votes
4 answers
13k views

Place a block inside a twig template

I've got a custom content type 'professor', and a 'node--professor.html.twig' in my theme (derived from 'classy') to override the standard markup. The designer wants me to put a list (a view?) of the ...
Kirill Kuvshinov's user avatar
5 votes
2 answers
9k views

Programmatically accessing block content

Could anyone tell me how to programmatically access the field content of a custom block? Thus far I've managed: use Drupal\block\Entity\Block; $block = Block::load($block_name); if ($block) { $...
Matthew's user avatar
  • 73
5 votes
4 answers
6k views

How to get the context node in a custom block inside a views list?

I have a view which displays all pictures of the content type photo. I've set some fields in this view for the display. This is how iIrender the list of pictures: views-view-fields--photo.html <...
Kevin's user avatar
  • 2,556
3 votes
2 answers
5k views

Render custom block using block.html.twig template

I'm attempting to render a custom content block programmatically (created through the Custom Block Library UI) and I would like the block to render using block.html.twig as it would if I were to place ...
maskedjellybean's user avatar
5 votes
1 answer
6k views

Use a twig template instead of a render array in a custom module admin page

I have a Drupal 8 custom module, and I want to display its configuration page using the admin theme. Usually, for this kind of pages I use, in the _controller property of my route, rather : a class ...
Eria's user avatar
  • 481
1 vote
3 answers
2k views

How to place facet block in views page header? (not regions)

I've created a search with Search API module and Facets module. I've added two taxonomy term name fields to my search index and created two facets for those fields. Just for testing I've placed the ...
Hudri's user avatar
  • 5,539
0 votes
2 answers
4k views

Render blocks in custom page

I followed steps given in this link to create a custom Page. Page is created and 'Hello world' is printing in the page, now i want to render some blocks in that page. How can I achieve this task?
rks's user avatar
  • 399
0 votes
1 answer
2k views

D8: render block in node?

We're migrating some code to D8 and in some of our nodes' body field we used to call PHP code directly with the now defunct module_invoke to render a block in the node before the content. All the ...
user avatar
2 votes
1 answer
2k views

Can't render a block due to recoverable fatal error

I had code to programmatically render a block. $block = \Drupal\block\Entity\Block::load('bartik_search'); $block_content = \Drupal::entityManager() ->getViewBuilder('block') ->view($block);...
Henry Tran's user avatar
0 votes
1 answer
2k views

how to know block id in class which extend from BlockBase

I am trying to get block id in my custom module in build function of class which extends BlockBase. How can i do this? i want to use this block_id in another class controller to have configuration ...
user780's user avatar
  • 1,029
0 votes
2 answers
1k views

Custom blocks created as a plugin in a module not showing for Block::load()

I have a couple of blocks that have been created using the ... extends BlockBase syntax in my module. They work perfectly fine, and I can add them on the blocks layout page, can add them into DS as a ...
Matt Fletcher's user avatar
0 votes
1 answer
640 views

Is there a way to get the controller class from a Request object or any other service class?

My controller class holds some not-so-easy logic to receive some data from a route parameter I need in a block plugin. As this block will only be rendered on this specific route, I would like to ...
Tobias Krause's user avatar
-1 votes
1 answer
694 views

How to print Blocks in commerce-product.html.twig?

I am looking at building a Drupal 8 Commerce 2 product display through twig but I am having issues with how to print custom blocks in this template file. (And also testing these in normal page.html....
IamOnStage's user avatar
1 vote
0 answers
583 views

Programmatically creating mulitple blocks without creating seperate .php files for them

EDIT: The code below works - there was a problem with my local machine - read more at the end for why it did not work I want to create multiple blocks that don't need custom setttings from the ...
GiorgosK's user avatar
  • 8,483

15 30 50 per page