Firefox 59 mit verbessertem Screenshot-Tool

heise online Newsticker - 15. März 2018 - 11:00
Firefox wird mit seinem neuesten Update wieder ein bisschen schneller. Außerdem verfügt das integrierte Screenshot-Tool über einige einfache Bearbeitungsfunktionen.

Heise lädt zum MINT-Jobtag nach Hannover

heise online Newsticker - 15. März 2018 - 11:00
Auf dem MINT-Jobtag am 21. März in Hannover präsentieren Arbeitgeber ihre Stellenangebote und tauschen sich mit Interessierten aus. Ein Rahmenprogramm mit Bewerbungscheck und Führung durch das c‘t-Testlabor macht die Jobmesse abwechslungsreich.

Fitbit Versa: Nachfolger der Ionic sieht aus wie die Apple Watch

heise online Newsticker - 15. März 2018 - 11:00
Fitbit hat mit der Versa seine zweite Smartwatch vorgestellt. Die Versa erinnert an die Apple Watch, kostet aber nur 200 Euro. Wegen der Perioden-Messung eignet sich die Versa vor allem für Frauen.

Matt Glaman: Another AWESOME MidCamp!

Planet Drupal - 15. März 2018 - 11:00
Another AWESOME MidCamp! mglaman Thu, 03/15/2018 - 04:00

 MidCamp 2018 has come and gone. This was the regional Drupal camp's fifth year, and my fourth time attending (missed year one ????). The amazing group of organizers behind the conference makes it one of my favorites. MidCamp is a human first event -- everything is about accessibility.

PreviousNext: Bare Templates: Removing Unnecessary Markup in Twig files

Planet Drupal - 15. März 2018 - 10:48

In most of the projects we build, the HTML markup provided by core just gets in the way. There is way too many wrapper divs. This can cause issues when trying to create lean markup that matches what is produced in a generated styleguide.

In this post, I'll introduce you to the concept of bare templates, and how you can remove unnecessary markup from your Twig templates.

by Pasan Gamage / 15 March 2018

In Drupal 8, a couple of themes are shipped by default to serve a common set of end user needs.

Among them are:

  • Bartik: A flexible, recolourable theme with many regions and a responsive, mobile-first layout.
  • Seven: The default administration theme for Drupal 8 was designed with clean lines, simple blocks, and sans-serif font to emphasise the tools and tasks at hand.
  • Stark: An intentionally plain theme with almost no styling to demonstrate default Drupal’s HTML and CSS.
  • Stable: A base theme. Stable theme aggregates all of the CSS from Drupal core into a single theme. Theme markup and CSS will not change so any sub-theme of Stable will know that updates will not cause it to break.
  • Classy: A sub-theme of Stable. Theme designed with lot of markups for beginner themers.

But in an actual business scenario the requirements and expectations of a client towards the look and feel of the website is far more distinct than the themes that are provided in Drupal core.

When building your site based upon one of these themes it is common to face issues with templating during the frontend implementation phase. Quite often the default suggested templates for blocks, nodes, fields etc. contain HTML wrapper divs that your style guide doesn’t require.

Usually the most effective way is to build themes using the Stable theme. In Stable, the theme markup and CSS are fixed between any new Drupal core releases making any sub-theme to less likely to break on a Drupal core update. It also uses the verbose field template support for debugging.

Which leads us to use bare templates.

What is a bare template?

A bare template is a twig file that has the minimum number of HTML wrappers around actual content. It could be simple as a file with a single content output like {{content.name}}

Compared to th traditional approach, bare templates provide benefits such as:

  • Ease of maintenance: With minimum markup the complexity of the template is much lesser making it easy to maintain.
  • Cleaner Markup: The markup will only have the essential or relevant elements where as in traditional approach there are a lot of wrappers leading to a complex output.
  • Smaller page size: Less markup means less page size.
  • Avoids the need for markup removal modules: With bare markup method we do not need to use modules like fences or display suite. Which means less modules to maintain and less configuration to worry about.
Our Example

We need to create a bare template for type field and suggest it to render only field name and field_image of my_vocabulary taxonomy entity. This will avoid Drupal from suggesting this bare template for other fields belonging to different entities.

Field template

Let's have a look at field template which resides at app/core/themes/stable/templates/field/field.html.twig

{% if label_hidden %} {% if multiple %} {% for item in items %} {{ item.content }} {% endfor %} {% else %} {% for item in items %} {{ item.content }} {% endfor %} {% endif %} {% else %} {{ label }} {% if multiple %} {% endif %} {% for item in items %} {{ item.content }} {% endfor %} {% if multiple %} {% endif %} {% endif %}

As you see there is quite a lot of div wrappers used in the default template which makes it difficult to style components. If you are looking for simple output, this code is overkill. There is however, a lot of valuable information is provided in the comments of field.html.twig which we can use.

{# /** * @file * Theme override for a field. * * To override output, copy the "field.html.twig" from the templates directory * to your theme's directory and customize it, just like customizing other * Drupal templates such as page.html.twig or node.html.twig. * * Instead of overriding the theming for all fields, you can also just override * theming for a subset of fields using * @link themeable Theme hook suggestions. @endlink For example, * here are some theme hook suggestions that can be used for a field_foo field * on an article node type: * - field--node--field-foo--article.html.twig * - field--node--field-foo.html.twig * - field--node--article.html.twig * - field--field-foo.html.twig * - field--text-with-summary.html.twig * - field.html.twig * * Available variables: * - attributes: HTML attributes for the containing element. * - label_hidden: Whether to show the field label or not. * - title_attributes: HTML attributes for the title. * - label: The label for the field. * - multiple: TRUE if a field can contain multiple items. * - items: List of all the field items. Each item contains: * - attributes: List of HTML attributes for each item. * - content: The field item's content. * - entity_type: The entity type to which the field belongs. * - field_name: The name of the field. * - field_type: The type of the field. * - label_display: The display settings for the label. * * @see template_preprocess_field() */ #} The code Building the hook.

We will be using hook_theme_suggestions_HOOK_alter() to suggest the two fields to use our bare template when rendering.

It is important to note that only these two fields will be using the bare template and the other fields (if any) in that entity will use the default field.html.twig template to render.

my_custom_theme_theme_suggestions_field_alter (&$hooks, $vars){     // Get the element names passed on when a page is rendered.     $name = $vars['element']['#field_name'];     // Build the string layout for the fields.     // :::     $bare_hooks = [         'taxonomy_term:my_vocabulary:teaser:name',         'taxonomy_term:my_vocabulary:teaser:field_logo',     ];     // Build the actual var structure from second parameter     $hook = implode(':', [         $vars['element']['#entity_type'],         $vars['element']['#bundle'],         $vars['element']['#view_mode'],         $vars['element']['#field_name'],     ]);     // Check if the strings match and assign the bare template.     if (in_array($hook, $bare_hooks, TRUE)) {         $hooks[] = 'field__no_markup';     } }

The hook key field__no_markup mentioned in the code corresponds to a twig file which must reside under app/themes/custom/my_theme/templates/field/field--no-markup.html.twig

Debugging Output

In order to see how this is working, we can fire up PHPStorm and walk the code in the debugger.

As you can see in the output below, the implode() creates the actual var structure from the second parameter. We will use this to compare with the $bare_hooks array we created  fields specific to content entity types that we need to assign the bare template.

Note: As best practise make sure you pass a third argument TRUE to in_array(). Which will validate the data type as well.

 

Bare Template Markup

The following is the contents of our bare template file. Notice the lack of any HTML?

{# /** * @file * Theme override to remove all field markup. */ #} {% spaceless %} {% for item in items %} {{ item.content }} {% endfor %} {% endspaceless %}

Bare templating can be used for other commonly used templates as well. To make it render a minimal amount of elements.

Conclusion

We can always use custom templating to avoid getting into complicated markups. And have the flexibility to maintain the templates to render for specific entities.

Resources Tagged Style Guides, Twig

EU-Studie zu "Fake News": Plattformen sollen Algorithmen offenlegen

heise online Newsticker - 15. März 2018 - 10:30
Eine Expertengruppe der EU-Kommission empfiehlt, im Kampf gegen Desinformationen im Netz die Transparenz im digitalen Nachrichten-Ökosystem deutlich zu erhöhen. Kritiker bemängeln, dass Clickbaiting nicht angegangen wird.

Digitalpakt für Schulen: Schüler sollen Tablets selbst mitbringen

heise online Newsticker - 15. März 2018 - 10:30
Der immer wieder verschobene Digitalpakt der Bundesregierung soll 5 Milliarden Euro für die IT-Ausstattung der Schulen bringen. Für die Endgeräte der Schüler ist dabei aber kein Geld vorgesehen, wie aus einer Antwort der Bundesregierung hervorgeht.

Amazee Labs: Launching Kinderregion

Planet Drupal - 15. März 2018 - 10:04
Launching Kinderregion

We’re super excited! The new Kinderregion website has finally launched and brings their motto of Great parents need great tips for trips to life. 

It showcases a wide variety of exciting activities for kids. Families living in Switzerland can now plan a fun day for the whole family by browsing the site. Built on the same framework as Zurich Tourism, Kinderregion showcases highly engaging content that is structured, helpful and of interest to the user. 

Nicole Blum Thu, 03/15/2018 - 09:04 The idea

By building Kinderregion on the same framework as Zurich Tourismus, the new site would have to to offer highly valuable content in a structured and appealing manner. The events section should benefit from the main site’s interactive features such as instant filters and an interactive map based on React. As Kinderregion is a content heavy website, we would need to allow content editors to easily change the front page and the menu. Similarly, we would need the ability to deploy code and configuration changes without losing the customisations done by the client. Just as with zuerich.com, our idea to solve this was using the Panels ecosystem.

The most challenging part of the project

Creating something complex on a tight budget can be tricky. We were, however, able to solve this by re-applying certain existing elements throughout the entire site. Along the way, our team learned a bunch of new things and strengthened their skill sets even more. One highlight being how to override existing styling when working with the sub-template.

The Result

We implemented Kinderregion as a subsite of the main Zurich Tourism website, based on the Domain module. This allows us to share mission content across both websites and most importantly, benefit from the infrastructure that the Zurich Tourism Website already provides. We also added to the permission system and the reactive events filter section on the Landing pages.

The same layout used for zuerich.com is applied to Kinderregion, and is based on the "Panels suite". It is built using "Panels everywhere", which enables us to export the site layout and it’s domain-specific variants to features. Following the same logic, the home page is based on a panel page with different variants for each domain. The mega menu is composed of mini panels, loading into specific menu items through the use of the menu mini panel module. The consistent use of panels for all of these different areas allows the content editors to easily update the front page and makes it possible for us to deploy code and configuration changes, without losing the customisations done by the client. Hence, the sites heavy content is displayed in a coherent and captivating manner.

We loved collaborating with Zurich Tourism again on this new project and also really enjoyed working alongside the creative agency Rosarot Ideennetz throughout the process. All input and guidance has been super valuable and highly appreciated.   

Eon und RWE teilen Geschäfte auf – 5000 Stellen sollen abgebaut werden

heise online Newsticker - 15. März 2018 - 10:00
Der Konkurrenzkampf zwischen Eon und RWE soll künftig vorbei sein. Die beiden Energieriesen wollen sich aus dem Weg gehen. Ein Deal, der nur Gewinner kenne, versichert RWE-Chef Schmitz. Doch auf die Beschäftigten kommen Einschnitte zu.

Nicht diese Art Croft: Tomb-Raider-Reboot bringt eine moderne Lara in die Kinos

heise online Newsticker - 15. März 2018 - 9:00
Lara Croft fährt jetzt als Fahrradkurier Fast Food durch London und hat statt zwei Pistolen Pfeil und Bogen dabei. Aber Tomb Raider bleibt trotzdem Tomb Raider.

Scala Days 2018: Frühbucherrabatt nur noch bis 15. März

heise online Newsticker - 15. März 2018 - 9:00
Die Scala Days Europe 2018 bieten im Mai in Berlin ein umfangreiches Programm mit namhaften Sprechern. Nur noch wenige Tage gelten vergünstigte Preise bei der Anmeldung.

IBM warnt vor dem Internet of Threats

heise online Newsticker - 15. März 2018 - 8:30
Das Industrial Internet of Things eröffnet Industrie und Versorgern viele Möglichkeiten, birgt aber auch gewaltige Risiken. Unternehmen sind hier schlecht vorbereitet.

E-Bikes: Verkauf steigt um 19 Prozent

heise online Newsticker - 15. März 2018 - 8:30
Elektrofahrräder kommen in Deutschland gut an, der Verkauf wächst. Anders ist es mit den Drahteseln, die nur mit Muskelkraft betrieben werden.

Zahlen bitte! 105 Tasten zum Tippen

heise online Newsticker - 15. März 2018 - 8:00
Heute dreht sich unser "Zahlen bitte!" um die PC-Tastatur. Bis zum aktuellen Standard mit in Deutschland üblichen 105 Tasten war es ein weiter Weg.

DIHK: Fachkräftemangel bedroht unter anderem den Breitbandausbau

heise online Newsticker - 15. März 2018 - 7:00
In vielen Branchen fehlt es an Fachkräften, sagt der Deutschen Industrie- und Handelskammertag. Abhilfe könnte die Digitalisierung schaffen – wenn die nicht gerade durch den Mangel ins Stocken käme.

Agiledrop.com Blog: AGILEDROP: Our blog posts from February

Planet Drupal - 15. März 2018 - 3:09
You have already seen what Drupal blogs were trending in the previous month, and now it is time to look at all our blog post from February.    The first blog post in February was What can Drupal agencies expect in 2018 by our Commercial director Iztok. He looked at the technology trends and how they are changing, how can those changes influence on Drupal agencies and what can we expect in the future. What are the conclusions from Drupal Business Survey, including responses from 200 different Drupal agencies? Iztok did a SWOT analysis based on digital agency reports from 2017 and outlooks… READ MORE

MTech, LLC: Drupal 8 Contrib Upgrade Status

Planet Drupal - 14. März 2018 - 22:13
Drupal 8 Contrib Upgrade Status

One of the things I constantly get asked about in the Drupal 8 migrate space is when will migrate be ready for use. With the API being marked stable in 8.5.0, now is a good time to consider upgrading. Upgrading a D6 or D7 site should be ready, especially if you have mainly core modules in use. However, what about when your site used a contrib module or two or ten?

Lucas Hedding Wed, 03/14/2018 - 14:13

Bericht: Apple verprasste Siris Vorsprung durch interne Querelen

heise online Newsticker - 14. März 2018 - 20:00
Ein wackliger Unterbau, mehrfache Management-Wechsel und Grabenkämpfe haben einem Bericht zufolge die Weiterentwicklung von Apples Sprachassistenzsystem massiv behindert.

App statt ÖPNV: US-Großstadt schafft Buslinie ab und subventioniert Ridesharing

heise online Newsticker - 14. März 2018 - 20:00
Arlington in Texas war lange Zeit die größte Stadt der USA ohne eigenen öffentlichen Personennahverkehr. Die erste Buslinie war dann kein Erfolg und wurde nun eingestampft. Stattdessen sollen Bewohner eine Ridesharing-App nutzen.

Das DNS ist in die Jahre gekommen: Braucht das Domain Name System ein Re-Design?

heise online Newsticker - 14. März 2018 - 19:30
Über 30 Jahre alt ist das DNS und mit diversen Ergänzungen mittlerweile schwer überschaubar. Braucht es ein Re-Design oder sollte man es gleich pensionieren?