> Blog

Inserting a Block Into a View Listing in Drupal 8

My blog homepage is basically an activity feed, a combination of Blog Posts, Short Notes, Images and Links, much like a facebook wall or a tumblog.  I decided I wanted to add a link to one of my other sites in the feed, basically a “house ad”.  Blatantly stealing from facebook, I decided that I wanted the second item in the feed. My goal is to create something like this:

In Drupal 7, I would have used preprocess_views_view to insert the ad into the view, but I wanted to do something that was more sustainable and not as hard coded.  Although on my blog I perform all roles (developer, designer, themes, content admin, etc), I wanted to give non-developers the ability to add, change and delete the advertisement.  So I decided to use Drupal's block interface.

I did a little investigation and found that the Twig Tweak module provides a twig function to fetch and drupal regions (and blocks, entities, fields and other Drupalisms). Here's a list of of the functions Twig Tweak provides. The drupal_region twig would do what I need.

Here’s what I did

  1. I added a region to my theme config, “view_inline_ad.”
  2. I added the block with the ad it to the region.
  3. Added the code to render the region to my views template (views-view-unformatted--blog.html.twig) {% if title %}

    {{ title }}

    {% endif %} {% for row in rows %} {% set row_classes = [ default_row_class ? 'views-row', loop.first ? 'views-row-first', loop.last ? 'views-row-last', ] %} {% if loop.index == 2 %} {{ drupal_region('view_inline_ad') }} {% endif %}
    {{ row.content }}
    {% endfor %}
  4. Cleared Cache, loaded the page and rock and roll.

One problem I ran into, on my site the blog theme is not the default theme. I host multiple sites out of the same Drupal instance and am using the Switch Page Theme module to change theme based on site context. drupal_region() assumes you're using the default theme and not the current theme so it couoldn't find the region. It does accept a second parameter, theme. I popped the theme's machine name in there and it worked like a charm.

Image
Laptop w/ Stickers

I Hate Video Conference Calls

I have to be honest, I really don't like doing meetings over skype. Don't get me wrong there's a benefit to having video on all participants, but now I feel I have to be a television producer as well as a technologist when I'm making these calls... I spend 20 mins before each call checking the lighting, the angle of my shot, the background. And I'm worrying:

How many chins do I have in the shot? Do I need to a light to prevent a shadow?

I have to camera test shirt / tie combinations, especially with older webcams.

Why am I wearing a tie anyway? Don't these people realize that if someone is working from home the main benefit is Pajama Fridays?

I worry if my shirt clashes with the paint on the walls or worse yet, if the shirt and background are close in color and I appear to be a disembodied head? (this happened to me once)

Of course this is followed by an audio test. Is my mic too hot? Am I close enough to it. Can they hear me breathing?

IF my allergies are acting up is my nose too red? Do I need to borrow some of Anne's makeup to tone it down or will I appear to be David Bowie if I do. What about the zit from when I shaved the other day?

I have to remember to lock up the cat so I'm not trying to shoo him away from the keyboard that he'll attack in the middle of the call.

Folks, really I'm bit of a neurotic mess every time we do video calls, can we just do voice calls?

Today I learned that English Muffins reproduce by budding.