Checking in Twig if a variable is null and concatenating it with another string and adding to an array if not

Just doing some basic things in Twig which i find i have to look up each time, ok not sure i ever did the null thing before, but anyway noting how here.

First some bonus Drupal. For some reason this is what worked to get the raw value out of the integer list field (no .value; that didn’t work anywhere):

{% set spacing = content.field_height.0 %}

Now the part of checking if the variable is null, and adding (appending) it to our existing classes array variable if not, using the tilde operator to join it to a piece of text as we do so. Note we still need to render it with |render because Drupal’s giving it to us as a render array, and that part is weird, sorry. (Non-Drupal people just ignore that; this is related to the previously mentioned surprise of .value not working to get the pure value.)

{% if spacing is not null %}
  {% set classes|merge(['h-' ~ spacing|render]) %}
{% endif %}

And here’s the rest of the code, for completeness, but all the learning is above this line! (Below note that while this is a template for a Drupal block, the term block below is for the twig contruct of blocks.)

<section{{ attributes.addClass(classes) }}>
  {{ title_prefix }}
  {{ title_suffix }}

  {% block content %}
    {# Cannot add card-img class directly to image tag from here but maybe it's not needed at all. #}
    {{ content.field_image }}
    <div class="card-img-overlay">
      <h2 class="card-title">{{ content.field_title }}</h2>
  {% endblock %}