Automatic Text Excerpt / Truncated Texts with Twig

Today I had to create a grid of cards for a search page. To ensure a consistent layout I wanted the excerpt texts to be cut off, if necessary, at certain length.

This can be done easily when using the truncate filter in the Twig template engine for PHP:

toLongText|truncate(14)

The number 14 stands for the number of words after which the text will be cut off and an ellipsis is added.

Goodbye OnePlus 5T – Hello Google Pixel 6A

Today marks the end of a small digital era for me – I am saying goodbye to my beloved OnePlus 5T. It’s the best smartphone that I’ve ever owned and served me very well for close to five years.

The OnePlus 5T smartphone laying on a table
Farewell to the best smartphone I’ve ever owned: OnePlus 5T

Why I Iove the OnePlus 5T

OnePlus is not a very well known brand here in Switzerland. But they managed to catch my attention back in 2018 by creating inexpensive smartphones that delivered rather strong performance. And for me, with the 5T they’ve ticked all the main boxes that a great phone should tick:

  • A good camera
  • Decent battery life and a very quick charger
  • Great software: near stock Android with no unnecessary modifications
  • Solid performance

These are also the main drivers that made me keep it for the longest time that I’ve ever had a phone. And it’s only now that it started to have lags in performance and limited charging capabilities that left me want to let it go.

I think it’s great and important that the smartphone industry has matured as much so a device doesn’t need to thrown away after two or three years.

Google Pixel 6A laying on a piece of wood. The Google logo is shown on screen.
Hello Google Phone

Switching to the Google Pixel 6A

I was thinking quite a bit about switching to an iPhone and possibly specifically the iPhone mini. Since I haven’t owned an iOS device for quite a while I’ve lost touch with the platform a bit. I couldn’t really tell however, if I would have enjoyed the trip back or not: I generally don’t really like their physical phone designs (although the mini form factor is fantastic) and rather dislike their general photo processing.

So long story short: I’ve seen the Pixel 6A in a shop today for 399 Swiss Francs (about 400 dollars) and took it. While it’s not a flagship I’ve checked it out previously and it seems like reasonable middle ground – probably more than enough smartphone for me. And I also imagined it would be a an interesting look into the Pixel series.

What I like about it:

  • It runs Android in it’s latest version and as Google imagines it. So far that is the best version of the OS that I’ve seen. I really enjoy using Android and also the latest Material You overhaul.
  • It’s not too large. It’s actually physically a bit smaller than the 5T although the display size is a bit larger.
  • It’s not fancy but yet seems to do the main things right and to check all the needed boxes.

I hope it will make a fine daily driver for the next years to come – wish me luck! 😉

How to disable the “Synchronise repeater and flexible sub-fields positions in post translations” WPML ACF option

The Problem

If you use WordPress and have WPML with their Advanced Custom Fields Multilingual (ACFML) plugin installed you may have already spotted the following option below repeater fields:

Option to synchronise repeater and flexible sub-fields positions in post translations
(record drag-and-drop moves and do the same moves in other translations).

While this may seem like a nice option it’s turned on by default and not great for websites that use a repeater as the main content field and have pages with varying content for different languages. I often use the Flynt theme for developing custom-made WordPress sites, which uses the given setup.

The solution: disable the “Synchronise translations” option by default

Sadly I haven’t found a documented way to disable the option. While looking through the ACFML plugin however I’ve found the following solution in two easy steps:

1. Add the following lines to your wp-config.php file:

/* Disable ACFML's sync of repeater field positions across languages by default */
define( 'ACFML_REPEATER_SYNC_DEFAULT', false );

2. Most likely: update setting of existing posts

In your database select the “wp_options” table and look for a record with “option_name” = acfml_synchronise_repeater_fields. This record seems to contain the post IDs of existing posts with their corresponding boolean setting.

Rename the acfml_synchronise_repeater_fields column to something like acfml_synchronise_repeater_fields_backup in order to disable/unset the value for all existing posts. As soon as you set the setting for a post again this record will be recreated.

Feedback appreciated

If this solution helped solve the same problem for you it would be great if you could let me know that in the comments below.

HTML5 Video Autoplay in Mobile Safari

For autoplay to work on Mobile Safari with a native HTML video element you need to also set the “playsinline” attribute. Otherwise the video wouldn’t start to play automatically:

<video muted loop autoplay playsinline preload="auto">
    <source src="video.mp4" type="video/mp4">
    Your browser does not support playing this video.
</video>

The playsinline attribute is actually a standard HTML attribute, I learned today. I did not encounter any problems with autoplay in other browsers besides within Mobile Safari though.

Next Steps: This Blog Now Has English and German Content

Maybe you have already noticed it (at least if you are an English speaking person 😉): this blog now has English articles and there is a language switcher on top.

I realized that I would like to write more in English but still want to keep the existing German content.

Generally I will keep the majority of articles, which are centered around tech and web development, in English and only write German if it’s something that is particularly relevant for Switzerland. Most likely I will not be translating articles from one language into the other, even though I would be technically able to.

If you should find any grammatical or spelling errors I would be happy if you let me know in the comments section below.