Skip to content

Instantly share code, notes, and snippets.

View RobertCastro's full-sized avatar
🎯
Focusing

Robert Castro RobertCastro

🎯
Focusing
View GitHub Profile
@radheymkumar
radheymkumar / Get current user in drupal 8
Created October 18, 2019 04:24
Get current user in drupal 8
get current user in drupal 8
Description: In drupal 7 we get the current user object by defining global $user but in drupal 8 this quite different. If you want to get current user object then follow below code.
$current_user = \Drupal::currentUser();
$uid = $current_user->id();
It returns user id of current user.
$user_mail = $current_user->getEmail();
It returns user email id.
@mgbckr
mgbckr / install_zsh_on_sherlock.sh
Last active April 8, 2024 05:49
Compiling and installing Zsh without root privileges on Stanford's Sherlock (https://sherlock.stanford.edu) for use in tmux
# Update 2023-07-20:
# I've recently switched to installing `zsh` via `conda` which is a lot less hassle.
# I added it to start automatically in `tmux` with
# `set-option -g default-shell "~/miniconda3/envs/default/bin/zsh"`
#
# # Install Zsh on Sherlock
# Installs Zsh with Oh-My-Zsh without root privileges
# on Stanford's Sherlock (https://sherlock.stanford.edu) for use in tmux
#
# ## Instructions
@leahtard
leahtard / node.twig.html
Last active June 9, 2022 18:32
Get file url in node for Drupal 8 twig template
{# Get URL of single file field #}
{{ node.field_file.entity.uri.value }}
{# Get URL of multi file field #}
{{ node.field_file['#items'].entity.uri.value }}
{# Trun into link #}
{{ file_url(node.field_file.entity.uri.value) }}
{# Check if there is at least one value #}
@raphaellarrinaga
raphaellarrinaga / drupal_8_twig_cheatsheet.md
Last active July 20, 2023 21:21
[Drupal 8 Twig cheatsheet] #tags: drupal8, twig, cheatsheet

Drupal 8 Twig cheatsheet

Please note I created that sheet as a personal side note/draft and not everything is fully tested. There could be errors or better things to do. So if you spot something wrong or something that can be improved, feel free to comment below and I will do the changes.

Getting Drupal 8 field values in Twig

Image path: {{ file_url(content.field_name['#items'].entity.uri.value) }}