• Development

    404 Error Serving a /libraries page in Drupal 8

    It took some time to figure out why I kept seeing a 404 error (page not found) on http://www.mysite.com/libraries. The issue seemed to only present itself on our Acquia environments. Ultimately I realized that there was a conflict due to having a “libraries” directory in the document root of the site (e.g., /docroot/libraries).

    It was a quick fix after realizing the cause of the problem; I added this to my .htaccess file, above the other index.php rewrite rules.

    The reason this wasn’t happening on my local machine is because I’m using nginx locally for this particular website; the .htaccess file isn’t used.

  • Development

    Joining Strings in a Drupal Views Field using Twig

    I have two optional fields on a Drupal 8 content type: City and State. Both are rendered as simple text.

    In a fields-based View I wanted to show the field output as “Portland” or “Portland, OR”, or “OR”.

    First, I added the two fields, State then City (the order is important). Next I excluded the State field from display.

    Finally, I opened the Rewrite Results pane of the City field and checked the Override the output of this field with custom text checkbox.

    After several attempts at using Twig’s joinreplacespaceless, and more, I landed on this simple solution as the rewrite text:

    Note the whitespace modifiers (hyphens). These are the key to getting  Portland, OR  instead of   Portland , OR .

    Also, we cannot just use  {{field_member_city}}, {{field_member_state}} because we could end up with  , OR if City is empty.