How to render button with class from Route in drupal 8, 9, 10

With the following snippet you can create a link or button with classes from a route.

Five ways of using the path twig function for route links in drupal 8, 9 or 10

Linking to routes in Twig has become much easier since the release of some updates in Drupal 8. Here are 5 snippets that help when linking to internal routes.

How to use entityQuery Exists condition with entity reference

This snippet returns TRUE or FALSE if an entity has a filled-in value on a entity reference on field_winner field.

How to pass variables to html render arrays with FormattableMarkup in drupal 8, 9 and 10

Mixing HTML with variables is common practice when developing custom applications. This snippet shows how to mix HTML and variables the correct way.

Rendering a node or entity single field only programmatically in Drupal 8, 9 or 10

You do not always want to render a full output or your entity. This useful snippet teaches you how to render a single field value output.

Link to a route in twig [Drupal 8, 9, 10]

You should never hardcode your URLs in drupal. They might change. Use the following generic method instead.

Get the url of an image in drupal 9 & 10 with an image style in twig

Sometimes you need the URL of an image in twig in order to use it as a background image or something. While there are ways to load them in twig, it is more appropriate to do this with a preprocess function. This makes your code more maintainable. 

Subscribe to Drupal