-
Notifications
You must be signed in to change notification settings - Fork 1
Styling and templates for sitewide search #195
Conversation
| } | ||
|
|
||
| // Search page form. | ||
| #views-exposed-form-localgov-sitewide-search-sitewide-search-page { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a class we can use instead of an id for theming? Following Drupal standards we should not theme by ID.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated this to use classes provided by views instead of the div
| } | ||
|
|
||
| // Search results. | ||
| ol.search-results { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not need to use the ol element here. Within BEM classes should be styled independent of what element they are placed on.
Adding default styling of an element.class means the base theme that wants to override this will have to use something that is at least as specific as this, if not more specific.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. This is now nested in the view class and have removed the ol element.
| padding: 0; | ||
| list-style-type: none; | ||
|
|
||
| .node--view-mode-search-result { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good if this template had an item in the classes array for this node type called search-result, then we could use that as our Block class in BEM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep - using BEM classes now.
| margin-top: 0; | ||
| margin-bottom: 1em; | ||
|
|
||
| h3 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we had a .search-result class in the classes array, then we could use .search-result__title here instead of theming a h3 element. Drupal standards say we should not theme by element if at all possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep - using BEM classes now.
| * @ingroup themeable | ||
| */ | ||
| #}{% | ||
| set classes = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should leave in the default drupal classes that we get with node node--unpublished etc.
Also, we could have a .search-result class here, then the other items can have BEM-based classes such as:
.search-result__title.search-result__content- etc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Search result template has been updated to user BEM classes and add the default Drupal node classes to the search result wrapper.
| <a href="{{ url }}">{{ label }}</a> | ||
| </h3> | ||
| {{ title_suffix }} | ||
| <p>{{ content|render|striptags|raw }}</p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a div and not a p so we can have more than one field rendered in the search result view mode. For example, an event might want to render the event date as well as a snippet of text.
<div class="search-result__content">
{{ content }}
</div>
I think ^ would be better, so we don't need to have specific templates for any other content types, they can all render whatever content the site builders decide they should.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep - using a div now rather then a p
| @@ -0,0 +1,95 @@ | |||
| {# | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks to me to be identical to a standard views-view.html.twig file. If that's the case, we probably don't need to add it here at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The difference between this template and the standard Drupal one is the view filters come before the header. This is so the search block appears at the top and the page and not under the 'Search results' heading.
Doing this in the template seemed the best way to achieve this. Are you aware of any other ways to swap page elements without CSS hacks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy with that approach. I have a slightly modified views template in my default setup, where I use a variable to set things like that, then the custom views template just calls the default template and sets the variable to true. You can see a short write-up of it here:
https://mark.ie/blog/printing-regions-in-views-in-different-places-using-the-same-template
|
Thanks for the review @markconroy, I'll go through and address all the issue you found tomorrow. The theming here is largely just to make things look okay. The actual styling should be reviewed and adjusted by someone who has more expertise than me on this. |
|
@cjstevens78 I have a query about the search region in the theme. Do you know why this was hidden in the mobile menu section? There's a requirement to add a sitewide search form to the header (localgovdrupal/localgov#256) so I moved the header region so it appears after the menus. See:
Is this going to cause problems? |
|
As the new theme is progressing this is just a stop gap for the demo site until the new theme is ready. Would be good to get this approved with the release of the search. |
danchamp
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stephen-cox Happy enough with this for a release given it will be superceded by localgov_base in due course.
cjstevens78
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. We dont use the sitewide search on Croydon so doubt it'll conflict.
Part of localgovdrupal/localgov#259