Hello,
How to display votingapi fields in a custom block ?
Thank you in advance !
1 Follow this tutorial to install 'Votingapi Widgets': 'How to Create a Voting System in Drupal 8'
2 Visit /admin/structure/block/block-content/types and add new custom block type 'My Voting block' See the screenshots below: https://i.imgur.com/gJtFn42.png https://i.imgur.com/ijKTIqQ.png https://i.imgur.com/ILUMzYE.png https://i.imgur.com/4GUsuct.png https://i.imgur.com/NVAx8CR.png https://i.imgur.com/mFNGkAf.png https://i.imgur.com/Lp7if8r.png https://i.imgur.com/lI1xGhS.png
3 Visit /admin/structure/block/block-content and add new custom block of type 'My Voting block' See the screenshots below: https://i.imgur.com/e4lLSYJ.png https://i.imgur.com/5w6Uvmm.png
4 Visit /admin/structure/block and place the custom block into the desired region. Then scroll down and click on 'Save blocks' button. See the screenshots below: https://i.imgur.com/JCol8h1.png https://i.imgur.com/kxBcIGK.png https://i.imgur.com/FUnDBzv.png https://i.imgur.com/YV8pVV9.png
Thank you for you answer but unfortunately it is not resolve my problem !
I have content type with voting api fields and I want to display node content in a block !
let's see My code !
I create a custom block programmatically !
public function build() {
$node = \Drupal::routeMatch()->getParameter('node'); if ($node instanceof \Drupal\node\NodeInterface) { $object = $node; }else{ $object = NULL; } return array( '#theme' => 'node_notice_comment_block', '#nodeNoticeComment' => $object, ); }
In my twig file when I display votingapi fields {{content.field_notic_vote}} nothing appears !
The following tutorials show how to display a node in a block: 1 'A Node in a Block the Drupal 8 Way' 2 'HOW TO CREATE A CUSTOM BLOCK THAT EMBEDS NODES IN DRUPAL 8'
How I can print the block node in a custom twig tpl ?
thank you !
If you followed the tutorial 2 then your block with embedded node will be rendered using 'block.html.twig' If you want to use your custom template then just copy content of 'block.html.twig' in it.
Comments
1 Follow this tutorial to
1 Follow this tutorial to install 'Votingapi Widgets':
'How to Create a Voting System in Drupal 8'
2 Visit /admin/structure/block/block-content/types
and add new custom block type 'My Voting block'
See the screenshots below:
https://i.imgur.com/gJtFn42.png
https://i.imgur.com/ijKTIqQ.png
https://i.imgur.com/ILUMzYE.png
https://i.imgur.com/4GUsuct.png
https://i.imgur.com/NVAx8CR.png
https://i.imgur.com/mFNGkAf.png
https://i.imgur.com/Lp7if8r.png
https://i.imgur.com/lI1xGhS.png
3 Visit /admin/structure/block/block-content
and add new custom block of type 'My Voting block'
See the screenshots below:
https://i.imgur.com/e4lLSYJ.png
https://i.imgur.com/5w6Uvmm.png
4 Visit /admin/structure/block
and place the custom block into the desired region.
Then scroll down and click on 'Save blocks' button.
See the screenshots below:
https://i.imgur.com/JCol8h1.png
https://i.imgur.com/kxBcIGK.png
https://i.imgur.com/FUnDBzv.png
https://i.imgur.com/YV8pVV9.png
Thank you for you answer but
Thank you for you answer but unfortunately it is not resolve my problem !
I have content type with voting api fields and I want to display node content in a block !
let's see My code !
I create a custom block programmatically !
public function build() {
$node = \Drupal::routeMatch()->getParameter('node');
if ($node instanceof \Drupal\node\NodeInterface) {
$object = $node;
}else{
$object = NULL;
}
return array(
'#theme' => 'node_notice_comment_block',
'#nodeNoticeComment' => $object,
);
}
In my twig file when I display votingapi fields {{content.field_notic_vote}} nothing appears !
Thank you in advance !
The following tutorials show
The following tutorials show how to display a node in a block:
1 'A Node in a Block the Drupal 8 Way'
2 'HOW TO CREATE A CUSTOM BLOCK THAT EMBEDS NODES IN DRUPAL 8'
How I can print the node in a
How I can print the block node in a custom twig tpl ?
thank you !
If you followed the tutorial
If you followed the tutorial 2 then your block with embedded node will be rendered using 'block.html.twig'
If you want to use your custom template then just copy content of 'block.html.twig' in it.