how to use fields from custom block in drupal 8 - drupal

Im new to drupal 8. This is my first time building a site so please help. I have created a custom block type by going to structure/block layout/ types/ add custom block type - 'Feature Boxes'. This block type has 4 fields for the 4 dif images, and 4 fields for the 4 dif links. How can i use the data from each field in my page--front.html.twig file.

Use this module:
Twig Tweak
Examples can be found here:
I'm not familiar with adding fields to blocks.

Related

Drupal 8 Twig Page Fields

So I'm just getting started with Drupal and Drupal 8 and have a hard time understanding accessing twig content. Ideally what I would like to do is require some fields using the structured content.
When a type of structured content is used I would like to load a specific twig template and access the fields by machine readable name. This will allow me to setup template types with specific requirements for content.
I'm struggling with 2 parts and maybe what I want to do isn't possible in drupal. The first part how do I assign a page template based on structured content type?
The second issue is how do print out specific fields. I'm able to print all fields using {{page.content}} but {{page.content.field_name}} prints nothing. I'm very confused how to proceed forward. I know I can use modules and assign them to sections but for structured data types this won't allow for rigid enforcement of data collection like structured content. Some of this content flows outside a single content area so I'd really like to do it in a main layout file.
Thoughts?
For defining page template based on content type:
You can have:
page--front.html.twig - For front page
page--user.html.twig - For user page
page--youtube_videos.html.twig - For content type (here it is: youtube_videos)
For print content fields, you need to goto node.html.twig
For image field: {{ content.field_image }}
For title: {{ label }}
Tag field: {{ content.field_tags }}

Drupal 8: Twig Grouping Template

How to overwrite views-view-grouping.html.twig template, when I habe view called "My view" and I am grouping rows with taxonomy term "Format"?
Thanks in advance!
Template file should be named as views-view-grouping--[view machine name]--[view block id].html.twig.
Enable twig debug in drupal 8 to get more helps regarding templates.

Theming node add form

I want to theme this page node/add/classified.
I tried creating page--node--add.tpl.php, page--classified--add.tpl.php, page--node--classified--add.tpl.php refreshing cache all the time...Nothing works
I tried also implementing hook_theme() and hook_preprocess_page().
If you want to create a tpl file for a particular content type as you mentioned in your post "node/add/classified", then I would suggest, you should go with the tpl name like this
Drupal 6 : page-node-add-[content type].tpl.php
Drupal 7 : page--node--add--[content type].tpl.php
in your case, this would be (assuming your Drupal version is 7.x):
page--node--add--classified.tpl.php
Hope it will help you.

Placing block inside a node (positioning block between specific elements in node's content)

Basically I created a webform and enabled it as a block, now I want to put that block inside a specific node. I can do that by placing it in a 'content' region and defining the specific node BUT it displays at the end of the content. Now how can I move it between specific elements inside the content?
The node is using a page-type....tpl.php which is used by 5 other nodes as well so I cannot change the code.
To visualize it looks like:
[ content ]
-description text-
-list of videos-
[ end of content ]
and I need to put my webform between the text and the video list. Is there a way?
There are many roads you could take, but since you said you're considering the template file: Why not use a node-specific template, since page is a node type?
Say you're on node/123, then you could use a template named node--123.tpl.php
(see Drupal 7 Template (Theme Hook) Suggestions) and embed your block right there.
Alternatively, you could provide a reusable token in a custom module via hook_token_info and combine it with the commonly used token_filter module. But that might be over the top, if it's just one node you need to touch.
For Drupal 7 a bit of a hacky way to display the contents of a block in content would be to enable the PHP Filter module. Then edit your node and switch to the PHP code Text format and add this code
<?php
$block = module_invoke('block', 'block_view', '1');
print render($block['content']);
?>
where '1' is the block id found in the URL when you edit the block and be sure to include the PHP tags.
Also see this page https://www.drupal.org/node/26502 for more information on placing blocks.
You can use the EVA module to add the webforms in the node as a field.
You basically create a view and choose the "eva field" option then you make sure that this view selects only the webforms you want to have and relates it to the node (the EVA module documentation has much better examples than I can provide).
After you have added it as a field you can place it anywhere in the node.
There is also the Block reference module that could help you.

Drupal 6 theme add / edit content form

Drupal 6 theme add / edit content form
In Drupal 6, we can add new content type "content-type".
We want to theme /node/add/content-type by template file.
We want to theme the edit form /node/$nid/edit of this content-type also by template file.
How to do this?
For this you need to understand the naming convention of tpl files in Drupal. This link will help https://www.drupal.org/node/1089642
According to documentation,
"http://www.example.com/node/1/edit" would result in the following suggestions:
page-node-edit.tpl.php
page-node-1.tpl.php
page-node.tpl.php
page.tpl.php
Either you can try adding content-type in the naming as suggested(I have not tried it personally), or if there are few customization to be done, adding a check like
<?php if($node->type == 'content_type_name') ?>
over available variables in "page-node-edit.tpl.php" will also do.

Resources