Still on Drupal 7? Security support for Drupal 7 ended on 5 January 2025. Please visit our Drupal 7 End of Life resources page to review all of your options.
I am trying to print an image field in a views template because I want to add a class to the rendered image field. How can I achieve this?
I tried this:
{{fields.field_image.content}}
it prints the rendered image just fine. But How can I add a css class?
this
{{ file_url(fields.field_image.entity.fileuri) }}
does not seem to give me the url of the image field. Is there any other way to achieve this?
Hi I need to create a side block using the parent items of main menu.
In my file.theme i wrote
$menu_tree = \Drupal::menuTree();
$menu_name = 'main';
// Build the typical default set of menu tree parameters.
$parameters = $menu_tree->getCurrentRouteMenuTreeParameters($menu_name);
// Load the tree based on this set of parameters.
$tree = $menu_tree->load($menu_name, $parameters);
I'm wondering if anyone could provide any help here. I'm pretty new to the php elements of theming.
I've found a couple of snippets of suggested code, but it all seems to just crash the site with a 500 error.
I'm using a zen sub theme. At this stage I just want to make the cart summary block show less information when unexpanded - and fit on one line.
I've overridden the tpl.php files for a node type and the login block. Ideally I'd like to do the same for the cart summary block, but I've had no luck even getting the template.php to reference it.
Is there a way to customize a block template just as there is a way to customize a node template?
For example, I want to create a custom block called "my-custom-block" and place it in my header region of my template.
I'd like to create something similar to "node--my-custom-block.tpl.php" and have the markup render. On a cursory search of the regular resources I can't find a straightforward way to do this - beyond just putting markup in the block body summary field, but that doesn't allow me to do any sort of custom PHP injections.
I have a view with one exposed filter ( Display sticky content - Do not display sticky content ) .
The thing is the markup is the same for both types of content. How can i print out a class for the sticky content so i can target it with CSS ? Im guessing this is achievable with twig. Can someone point me in the right direction?