How to override a block template created using views - php

On Drupal 8 I'm trying to override the template of a block created using views. So far I've a file name as block--views-block--xxx.html.twig which gives me access to the view fields.
I've to do something like content.view_build['#rows'].0['#rows'] to get the rows which is pretty awful but I couldn't find any other way. Also I've to set "Show content" on the views settings.
I can not get the pager to work at all. Reading the documentation from Drupal I can not find any clues.

Turn on twig debugger (he's showing, in inspector tools, all templates what used now).
In inspector tools you see something like this:
- html--internalviewpath.html.twig
- html--node--id.html.twig
- html.html.twig
Then just create template with this name add you custom architecture. For example: html--node--id.html.twig. Check you can hear to, you see this:
- html--internalviewpath.html.twig
+ html--node--id.html.twig (now twig use this template)
- html.html.twig

I think you should rather override the view template rather than the view-block template.
View templates Naming conventions can be found here and the variables you can work with are listed here. you can now put the pager, header, rows and other view elements in different sections in template.
If you need to override the contents of the view rows then you will need to take action according to how you are displaying the content in the view.
If you use a teaser view of content you can override the content teaser template like "node--content_type--teaser.html.twig", or if you use fields in view then you will have to override the fields templates of each field.

Related

What is the best way to create page in Drupal 8 so that I can then add these posts with images?

I have a Home page on the Drupal website (such as is created after installation), but I still need to create this page:
What is the best way to create a page so that I can then add these posts with images?
I am just starting to learn Drupal and have heard so far about such ways of creating pages:
1) in admin toolbar: Content / Add Content / Article
2) in admin toolbar: Content / Add Content / Basic page
3) in admin toolbar: Structure / Views / Add Views
Which one should I use? Or maybe there is some other option that I don’t know about?
P.S. At the moment I am more interested how to create empty page on which I can then add posts later, and adding posts it is another question.
Welcome to Drupal.
Drupal ships with the default theme which won't look nice but it does its job in the right way. Now if you want to create a better UI/UX obviously you should create a new theme. But before that make sure to read and understand the concepts behind Drupal. Drupal docs are your first friend.
Drupal Documentation
Drupal considers everything as nodes and that's how Drupal got its power. As you mentioned, Articles, Basic Page etc are called content types and they can be used to create a particular type of content.
Now for your purpose create a new content type and add the fields you need. From the image above I can say your content type needs Title, Image, Category and Date. After creating content type you can create as many contents as you want under the content type you just created. Consider each card in your image as content.
Now you can use a Drupal Core Module Views, to perform DataBase Operations without writing single code. Yes, you can select fields, sort, order etc with Views UI and display it in a page or a part of a page (Block).
I would say just try this out in the default Drupal theme and when you understand how this works, you can start creating your own theme for your project.
Theming Drupal
There is a lot of resources available. But you have to make sure what you are asking is whether you actually need. It will take some time, but it worth.
To build layouts for homepages on Drupal 8 you best friend is https://www.drupal.org/docs/8/core/modules/layout-builder
To build the content blocks inside your home page, you should start creating nodes on a node content type to hold your information. For instance: news content type, with a title, a body, a date, and an image.
For every node type, ex. news, work on the preview display, full display, and any other display which makes sense. These displays can be used later in the Layout Builder directly or in Views, referenced below.
If you wish your list to be dynamic, such as the last 10 entries are shown first, then use a view to hold the content sorted and filtered as you need.
In a nutshell.
Create a content type for your article/news.
Modify the displays of the content types to have at least a summary and full view.
Create the content itself to have something to see.
Create the view (block) to filter and sort your content.
Create a page layout (this makes sense for landing pages) which places your new view and any other content you need in any disposition.
This is roughly what I would do. The steps described above contain many intermediate steps. If in doubt, check the docs.
I hope that helps!
First, decide what will you display on that page. Is it content in some existing content type (article maybe) or you want to crate new one for this purpose.
If you need new one then create it (Structure -> Content types -> Add content type).
Then check what fields will you need. I.e. image, some description text. Add missing ones.
Create few nodes (pages) in that type so you could work with them.
Then for displaying you should crate a view (Structure -> Views -> Add view). It can be a page view (you are displaying only that content on page) or block view (this is just a block among some others). If you create a page you could visit it and if you create a block you have to add it to some region to appear on page (Structure -> Block Layout).
Inside your theme you should create templates for this page/block. Turn on twig debug mode so it will show you hints - what templates are used and how can you name yours to override default ones.
Adjust CSS to make it look like you want it to look.
Find some tutorial(s) for the details
Previous answers have given the flow of the work you should go through, I would like to add some resource that might help you achieve this.
Creating content type and fields: https://www.drupal.org/docs/administering-a-drupal-site/managing-content-0/working-with-content-types-and-fields
https://www.drupal.org/docs/user_guide/en/structure-content-type.html
View and View modes: https://www.drupal.org/docs/user_guide/en/views-concept.html
https://www.drupal.org/docs/8/api/entity-api/display-modes-view-modes-and-form-modes
Handling block of the view: https://www.drupal.org/docs/8/core/modules/block/overview
Feel free to ask if any further explanation is needed.
Thank you

What does mean 'default_' part of a template view in a component?

I have noticed that a name of a template in joomla's component view begins with "default_" part. What the reason for it, how it can be changed?
you can simply create different template overrides as you like. F.ex. in com_content article view, make a copy of default.php and call it simple.php. You can display the new article template by calling index.php?option=com_content&view=article&tmpl=simple&id=an-id.
The _ - notation is to be able to divide the template into logical parts. F.ex. for the category blog-layout you have blog.php as the entry-point. The blog-layout is looping throug the content items in the category, and calling blog_item.php for each article item. So code relating directly to each article is handled here. If you override files in the template, you can choose to only override one of the files( like blog_item.php ), and let the other file get handled by by the component as usual.
regards Jonas

more than one text separator style per template in joomla 3.0

Let me first explain what I am trying to do.
In joomla 3.0 I have created a Menu_Item_Text_Separator override for my template http://docs.joomla.org/Help30:Menus_Menu_Item_Text_Separator. It seems as though joomla will only recognize one default Text separator per template which is ok if you just want the one. but I ideally would like to have the choice of selecting the custom one in my template folder as well as the default one that joomla recognizes. To inform you this is what I have done to make it happen.
in my template I have a folder named html which had a folder called mod_menu inside it.
In the mod_menu folder I have the .php files called:
default_separator.php
custom_separator.php
I then go into menu manager and edit the menu item for which I want to display a text separator for.
I then go to 'template style' http://docs.joomla.org/Help30:Menus_Menu_Item_Text_Separator and look for my custom style. but I only can choose the default one.
So i wonder if this is way that joomla works that you can only have one default per template. but is it possible to have more than one?
any advice most welcome.
regards
w9914420
Sorry this got too long for a comment.
Okay let's start from the beginning. Templates have a set of parameters defined in the templateDetails.xml file. A template style is simple a record containing the information about a template and the array of parameter options you have selected. You can make as many template styles as you want for a given template Each one has its own name. In the menu you can select any of the styles and assign it to a menu item. ....
What you are talking about has nothing to do with template styles. You are talking about using a layout override for mod_menu. Because you are using a file with the same name as a core layout file you should get a 1:1 replacement.
From what I understand of what you want to do, you should instead make a new named replacemen both for default_separator and for default.php. THat's because the alternative layout field is going to look for a replacement for default.php say yourname.php and then in that replacement when you load a template called separator it is automatically going to look for yourname_separator rather than default_separator because it assumes you are appending the _separator to the base name. If you do this it has some advantages such as you will be able to make a more complex layout and it will allow you to load different sub layouts conditionally for example.
I think your are confusing template styles with the style for menu module. Unless you have a parameter in your template that specifies the choice of a mod_menu layout a template style is not going to help you.Go to he module manager and pick the module you want to apply the style to. Use the field to select the layout you want. Or if it is a css style use the style option. It could also be that what you really want is to apply module chrome. THat do can be done by editing the module. If you want to have the same menu with different layouts or styles you'll probably want to make additional modules for that menu.
I had a rethink of what i was trying to do. What I was trying todo could not be achieved through the method I hoped - creating a template for that one text separator would not be practical although I have now discovered how to feed template parameter values into layout overrides.
Thank you Elin for your time
regards w9914420

Drupal 7: Custom 'Node Submit' Page through Views?

I'm a designer (read: I know Photoshop) with HTML/CSS skills, and limited PHP skills. I've done some Drupal templates, I've worked with views, panels, etc. So I can't create modules.
Can I still use the Form API (inside views, through rewriting field output for example) to create a custom "Submit Node" page?
If so, how would one accomplish this?
I believe it requires much coding to achieve that.
To get yourself started in rewriting views output, go to your views page "admin/structure/views/view/VIEW_ID/edit" -> Advanced section -> Theme: Information at the very bottom of the list.
Display output section: all the template suggestions that can be applied to the whole view (only one template can be applied).
Style output section: any template in this section is applied to every row of the view result.
Row style output section: any template in this section is applied to every field in each row of the view result.
Then you will find template suggestions to every field in the view.
http://views-help.doc.logrus.com/sites/all/modules/views/help/images/style-breakdown-large.png

how can I output the link or path with drupal views and customfield?

I have a view which lists some nodes and I want a custom output for the title of the node. Im using customfield which allows me to write PHP code but I cant find how to output the link to the node? It doesnt appear in the $data object. I can add the field, but still cant use it in the customfield code
Rather than using Views Custom Field to load PHP into the database, consider modifying the views template for the title field. If you go to Theme Information, it'll give you the file hints for the field. Create the file in your theme, and modify the title that way.
This has the benefit of separating code from content, and if you do it this way, you can add the Note: Link field, exclude it from the display, and use it in the Title template you created.
Check out Group 42's Guide to Theming for more information.

Categories