Please tell me how to add a header area on this page. Photo below.
Declare any new regions in your THEMENAME.info.yml file.
Print your region in page.html.twig.
If you declared
header: 'Header'
then you will print it in page.html.twig like this:
{{ header }}
After that you can create your custom block and place it in the newly created region.
For more details and info go to Drupal 8 Docs.
Related
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 }}
Here is the twig variable being set
{% set link = content.field_external_quote_link %}
When I just display the variable, it is coming out wrong.
For example if I do this in the HTML below:
TEXT EXAMPLE
It is dumping out devel code and other things I don't want. Is there something I need to do with the original variable set to get it to just dump the url in plain text?
{{ link.0.url }}
or
{{ link[0].url }}
or
You can make {{ link }} work, if you change your field settings within the node type display setting page, like this:
Goto your content type settings.
Goto: Manage Display
For the desired field, change format to display value as plain text or URL only.
WHich will tell drupal not to render it.
Now, clear cache. And, check again. It should work.
I am a new in Drupal. I want your help for doing this please help
I have created one Content type with fields( Title, Body, File) and also added content through this content type. But Some of the content didn't have file filed and some of the content having the only file. In the view, I want to show both either body or file. if suppose file field is empty then it should display the body of the same content.
Thanks.
You could do this by creating a custom node template for particular content type. So if you have a content type 'news', for example, the you can create a node template for this content type and customized the front-end display of the content. See below how it would work.
As per the Drupal theme suggestions, create a node template, named, node--news.tpl.php (copying the existing node.tpl.php file) in your custom (active) theme directory under the templates folder. On this template, you will be able to access the $node object variable, containing complete node information including fields and data.
Suppose your fields are field_image and body then replace your template's code print render($content); with the following lines:
if(!empty($content['body']){
print render($content['body']);
} else {
print render($content['field_image']);
}
For more details: https://www.drupal.org/node/1323842
Hope this help!
I want to add different header file to custom wordpress page template.
I created a new template for custom post type. I want to add a header file to it using get_header() function, but do not want to use the regular header of the theme. I can paste the entire changed header file into the template, but I don't think that is the correct way. Any suggestions would be helpful.
Thanks
you can create the header file for every template, for example, to call header-blog.php:
you need to get_header('blo');
I would suggest only replacing the content in the header-file based on the template.
You can therefore add a block just for the template "about.php" like this:
if(is_page_template( 'templates/about.php' ) {
//custom header for about.php
} else {
//Header for all other pages
}
You just create a different header file in you current theme
just like header-custom.php
This example will include header-custom.php
<?php
get_header('custom');
?>
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.