Questions tagged [navigation]
Use it for questions about navigation menus and links used in a site.
1,593
questions
59
votes
14
answers
121k
views
How to get the valid URL of a Link field from within a Twig template?
I have a Link field named field_my_link (machine name).
Within a Twig template I can get the link's URL value with this:
{{ node.field_my_link.uri }}
If inside the Link's URL there is an external ...
36
votes
10
answers
92k
views
How do I create a link?
Say I am extending The blockBase class to create a custom block, and I am implementing the blockBuild method to create some markup for my block. Something like this:
class YourModuleBlock extends ...
27
votes
6
answers
30k
views
How to add module to admin/config page?
I'm working on a module in Drupal 7. I've added a hook_menu implementation:
$items['admin/config/content/mymodule'] = [
'title' => 'MyModule',
'description' => 'Configure ...
23
votes
4
answers
19k
views
Non-Clickable Menu Items
In a Drupal 8 site, I want to add menu items with "no link", I was thinking that nolink is allowed but when I entered this, I got error
Manually entered paths should start with /, ? or #.
Is ...
22
votes
7
answers
14k
views
How to create an EMPTY anchor-only link with l()?
I'm trying to use l() to get something like <a href='#' ...>, for ajax-calling purposes. https://stackoverflow.com/questions/1698453/drupal-creating-anchor-only-link-with-l is very close to the ...
17
votes
10
answers
27k
views
Add class to content field (link)
I want to add a class to the <a> tag of a field that consists of a link and text. (It's a field of type Link.) The name of the field is content.field_c_button_link.
In the template file, I ...
16
votes
3
answers
16k
views
How can I add items to the Admin Toolbar?
In Drupal 8, I want to add a menu item to the Admin Toolbar with a submenu, with different links.
How can I do it?
15
votes
5
answers
28k
views
Programmatically create a menu
How can I programmatically create a menu? I have 3 different menus I want to create: The first menu will be placed in the top left of the header; the second menu will be placed below the first menu; ...
13
votes
4
answers
26k
views
How do I create menu links programmatically?
I need to add some links to existing menu (or to new) programmatically in Drupal 8.
13
votes
5
answers
5k
views
How to display more than 10 items in link widget autocomplete?
This is a question about the Link module. Since with the Link module you can enter external or internal links both, we strongly rely on it.
Unfortunately the number of items to be displayed from its ...
12
votes
4
answers
9k
views
Export menu configuration [closed]
Looking for a way to export menu configuration. The Configuration management system will export the menu itself, but not the menu links configuration. I am looking for a way to put one of those mega ...
11
votes
4
answers
4k
views
No navigation links on 404 pages
When I visit a page that does not exist, I expect to still see the primary and secondary links as on any other page, but what I get is no navigation links in the 404 page. See also No navigation links ...
11
votes
7
answers
17k
views
How to add fields to menu items
I need to build a main menu that is a subset of the regular menu. The design team thinks it would be better for user to have only the most important links in the main menu and not have everything. ...
11
votes
2
answers
312
views
What is the reason behind the current menu structuring
I'm not much of a Drupal Ninja; from what I saw at http://drupal.org/node/788972,
Drupal seems to have a menu structure like Joomla, in the sense that it allows menu items to be created under menu ...
10
votes
3
answers
20k
views
How to set target="_blank" for links in CKEditor
I use CKEditor in Drupal 8.
I want that every link will open in a new tab of browser. I want that the code look like this
<a href="#" target="_blank">my link</a>
But if I use the ...
10
votes
3
answers
15k
views
Render menu in twig template
In admin/structure/menu I created a menu. Is it possible to render this menu (with machinename: my_menu) in a twig template? Somehow like:
{{ my_menu }}
10
votes
6
answers
22k
views
How to add a Login / Logout link in Main navigation menu?
How can I add a Login link to the "Main navigation" menu?
When a user clicks on the link, it should take them to the /user/login page. Once they login, the link should change to say "Logout" instead ...
9
votes
2
answers
11k
views
How to turn a menu tree into an associative array?
I've dig into Drupal menu core to find out a way to build an associative array from a menu tree(eg,the account menu) so that I can output the data as json format. But it seems not possible to do this ...
9
votes
2
answers
6k
views
Remove the 'read more' and 'Add new comment' links on the home page
How do you remove or modify the list of links shown after the content?
9
votes
2
answers
7k
views
What is the equivalent of hook_translated_menu_link_alter() to alter a menu link? [duplicate]
I want to alter the menu link in Drupal 8. In Drupal 7 we can achieve this using hook_translated_menu_link_alter().
function module_translated_menu_link_alter(&$item, $map) {
global $user;
...
8
votes
5
answers
8k
views
Is there a way to order views grouped fields?
I am using views to group a list of nodes by taxonomy term and display these groups as accordion headers (displayed by the views accordion module).
eg:
Yellow:
node1
node2
Green:
node1
node3
...
8
votes
2
answers
10k
views
How to programmatically add links to the links variable
I am using Drupal 6 and would like to modify the $links variable to include other links programmatically. I have searched high and low on Google on how to do this to no avail. Does someone know how to ...
8
votes
2
answers
11k
views
How do I alter a language item link?
I am looking to modify the default output of Drupal 8 of links in a certain situation, the language switcher. Ideally I want to be able to do that in a twig template and not have to produce a massive ...
8
votes
3
answers
5k
views
How do I alter the title of a menu link?
In my website, users can collect some 'points' over time. I have a top-bar menu with some links (e.g. "home", "profile", "logout"). I want to alter the menu item "profile" and add the number points ...
8
votes
1
answer
2k
views
What's the "Drupal" way of creating image links?
I know that the correct way to create links in Drupal is to use l($text, $path, array $options = array()). But that only allows for text links. Is there a similar function for creating images that ...
8
votes
1
answer
4k
views
Create a new Menu in Drupal 8 programmatically
Is it possible to create a new Menu in Drupal 8 programmatically using a custom module?
I am creating a custom module, and one of the requirements of the module is that it creates a new menu under ...
8
votes
3
answers
5k
views
How to add confirmation to ajax link?
I am rendering ajax link as follows:
l(t('Click here'), 'mypath', array('attributes' => array('id' => 'my-id', 'class' => array('use-ajax'))));
How to display confirmation dialog before ajax ...
8
votes
1
answer
7k
views
Replacing menu items with images
I'm looking for a way to display a menu items as images (with rollover) rather than the usual text links. I found the module Menu Icons, but as the name implies, it's designed to place the icon next ...
7
votes
2
answers
12k
views
Can we add the destination query parameter to a link from yml configuration?
When creating a link from yaml
ie: mymodule.links.action.yml
my_module.my_entity.add:
route_name: node.add
title: 'Add My Entity'
route_parameters:
node_type: 'my_entity'
appears_on:
...
7
votes
5
answers
4k
views
How to Rename "Request new password" link?
We want to rename the "Request new password" text on a Drupal's login page to some custom text.
In the user.module file, I see that this text is hard coded
if (variable_get('user_register', 1)) {
...
7
votes
3
answers
13k
views
add a link to admin menu bar
I want to add the link to tags i.e. /admin/structure/taxonomy/tags directly to admin menu so that it appears next to "Content" link present on admin menu. How to do it?
7
votes
5
answers
9k
views
Hiding link from anonymous users
How can I hide a particular link in the main menu from anonymous users without making the whole menu invisible?
7
votes
5
answers
12k
views
How do I programmatically update or delete menu items?
I have seen How do I create menu links programmatically? but how do I update or delete menu items in Drupal 8?
By programmatically, I mean dynamically; YAML configuration files are not going to help.
7
votes
2
answers
3k
views
Create a link pointing to #
I am trying to make a link pointing to # but am unable to find a method that works.
The output i would like to see is
<a href="#">Example</a>
I have tried a few variations of the ...
7
votes
5
answers
6k
views
How to create a menu for current book
I want to create a menu that will be shown on the node if it is part of a book. For example like this:
That menu should be shown for all books, which means I don't want to have a separate block for ...
7
votes
2
answers
2k
views
managed links in Wysiwyg?
I am looking for a systematic way to deal with links in Drupal, like there is for images.
For images, you add image field to content type, then install "Insert" module and you can use Wysiwyg to ...
6
votes
1
answer
22k
views
Show all nested menu links in Drupal 7
How do I display all nested links in <ul><li> format in Drupal 7? The default code only displays the 1st level links even though they are arranged in the Drupal admin menu as nested:
<?...
6
votes
4
answers
5k
views
Migrating link fields to Drupal 8
I am trying to migrate a link field field_url from a Drupal 7 site to my Drupal 8 one. The link field is compound, it has a title and a url value. In my process plugin I am selecting the right values (...
6
votes
1
answer
8k
views
Drupal 8 Permission to see Structure > Menu
Drupal 8. I want a user with a certain role to be able to see and administer menu items /admin/structure/menu/manage/main
On the permissions page /admin/people/permissions I have 'Administer menus ...
6
votes
3
answers
20k
views
How do I add classes to main menu ul and li?
I want to generate the html elements and their classes to fit my styling of the main menu.
I'm confused by all the near-possibilities offered in the api documentation and by looking at core themes etc....
6
votes
2
answers
11k
views
how to make a field in a view be the link destination to another field?
I am trying to create ads on the sidebar to my site. I have created a content type that has 2 fields; an image field, and a link field. I now want to display the ads in a view by having the image ...
6
votes
4
answers
13k
views
Open a link in a new tab in the menu [closed]
I'm using Drupal 8 with Bootstrap theme, and I've created a sub-theme and different menus.
I've tried to edit the menu twig template but i am not really familiar with Twig.
How can I add a menu ...
6
votes
3
answers
3k
views
How can I add cache context to custom menu link?
I have two routes that receive user as route parameter, and i need a menu link for every one in account menu. So I added in my *links.menu.yml
client_account_links:
deriver: \Drupal\my_module\...
6
votes
3
answers
16k
views
Convert link from node/nid to Pathauto url?
Im using Pathauto to make my URLs nice and I may want to change the paths in the future. On some pages Im manually lining to other nodes.
The issue is that if I code the nice URL then the link will ...
6
votes
1
answer
4k
views
How to show contextual links buttons in templates with minimal markup?
I want to get rid of the most markup in Drupal 8 templates, but still want to have working contextual links. How to do this?
6
votes
2
answers
3k
views
How can I add a span tag inside my menu link?
My twig file contains the following:
<li{{ item.attributes.addClass(classes) }}>
{{ link(item.title, item.url) }}
</li>
Which outputs:
<li class="menu-item item--search">
&...
6
votes
2
answers
4k
views
Adding classes to menu items to signify what level they are
How can I add classes to the <a> or <li> tags of the main menu to signify which level they are in the menu hierarchy (e.g. "level-1", "level-2", etc.)? The code below shows the first link ...
6
votes
1
answer
3k
views
Create menu tabs with views
How can create menu views tabs of node? In Drupal 7 i can create views like this:
when i visit node/1/teaser it's show good.
But with same setting in drupal 8.
when i visit node/...
6
votes
3
answers
6k
views
Dropdown Menu Dummy Link
One of my menu items I have, I want to make it so that only the child links are clickable, and the parent is not. Is there a way to make the parent a sort of "Dummy Link" just to set a hierarchy for a ...
6
votes
2
answers
3k
views
How can I load a menu programmatically with an active trail set by a provided URL?
Working on a headless Drupal site, and have come across an issue. We have a REST resource that returns arbitrary menus by menu-id, however they always have "active-trail" set to false on every menu ...