The percent sign is something I once saw in Drupal 6 and 7. I didn't see it in views in Drupal 8; I don't know what was the reason to use this as it was in codes I've seen in a glimpse (It was a few years ago, I don't recall where exactly inside views but most probably inside filter criteria regarding a filtering via URL).

My question can actually be comprised of the following two questions.

  1. What is % in View's arguments?

  2. Is it something unique to Linux/PCRE/Drupal-itself?

Thank you,

| improve this question | | | | |
  • Can you please update your question with information about what version of Drupal you are running, along with a little about the dev environment; also a screen shot of the view or some context about where you are seeing this? Thanks! – Christia Dec 23 '16 at 4:03
  • Your question is unclear. Can you provide an example of what your exactly asking about? Are you asking about using a % in the views page URL? What version of Drupal? – nvahalik Dec 23 '16 at 4:04

The percent sign in view arguments is to tell Drupal to expect a contextual filter within the view path. It is specific to Drupal 6 and 7, linux doesn't matter.

Drupal 8 uses curly braces to accomplish this instead.

From https://www.drupal.org/node/1578576, the example provided is that user/%/comments would provide a contextual filter to show the comments for the specific user.

This resource gives screenshots and examples about how to create a contextual view filter: https://www.drupal.org/node/1578564

| improve this answer | | | | |
  • Thank you Christina for the didactic detailing. Can you please try to clarify with a theoretical example only the sentence "expect a contextual filter within the path"? I am not sure I understand it right. Thanks again, – user16289 Dec 23 '16 at 4:14
  • I don't have any such specific scenario but if you consider inventing any short theoretical example, I encourage you to do so... – user16289 Dec 23 '16 at 4:19
  • 1
    % is a place holder for a parameter that it will receive basically. So the URL in Christia's example it will actually match: user/PARAM/comments and PARAM will be processed to see if it's a valid User (in this case). If it's a user ID, it will be a user's UID. – rovr138 Dec 23 '16 at 4:41
  • Actually it does work this way --- You did gave an example and I missed it; I know re-read the answer and found out what I missed. I know understand it uses us to dynamically filter view results in certain contexts, like when letting a user to view all comments it published (Drupal will know who's the user seeking the comments via the dynamic pattern (%) in the URL and hence adjust the content). – user16289 Dec 23 '16 at 4:49

Here, you can see the User ID in contextual filter which we use in our view path, i.e see in the Path settings : "/user/%/profile".

This is an example for you to understand how to use % in view's path.

enter image description here

| improve this answer | | | | |

If you click on your view page path, it tells you:

enter image description here

and as you can tell from the screenshot, it is still used in Drupal 8.

If you still do not understand, basically it is a place holder. Whatever the % value is, it gets passed for your contextual filter.

Ex: view path of hello/%

When you go to yoursite.com/hello/benia, it automatically passes the word benia to your contextual filter.

Ex2: in /user/%/profile when you go to /user/10/profile it atomically passes the 10 to your contextual filter, thus only the stuff related to User ID of 10 shows up.

You could go to /user/sdlfkjlsadfklsdfja/profile and it passes sdlfkjlsadfklsdfja to your contextual filter, but since this value is no good, nothing shows up in your view page.

| improve this answer | | | | |
  • How can you use that for taxonomy paths? Like vocabulary/terma/termb etc – Bruno Vincent Sep 27 '17 at 1:38
  • @BrunoVincent vocabulary/terma/termb is this suppose to show a and b? – No Sssweat Sep 27 '17 at 3:10
  • Supposed to show terma and termb, or a and b , or cats and dogs, whatever;) Name of taxonomy in URL divided by slashes, vocabulary/a/b or vocabulary/cats/dogs – Bruno Vincent Sep 28 '17 at 1:08
  • Maybe my example is wrong, let me rephrase, taxonomy items in URL separated by slashes and from larger to small taxonomies, for example like this: usa/georgia/atlanta/atlanta-activities.htm, where atlanta-activities.htm is the final destination content item , USA is a vocabulary, and Georgia & Atlanta are taxonomies – Bruno Vincent Sep 28 '17 at 1:37
  • @BrunoVincent sorry I couldn't get back to you sooner. I've been busy and your question slipped my mind. If I were you, I would create a content type for the activities. Then add fields of taxonomy reference for each. Ex: Country, State and City. Create a new node, and assing City: USA, State: Georiga, City Atlanta. Create a view block and place it on the Activities nodes. Use Pathauto to make the activities page be [tax term country]/[tax term state]/[tax term city]/[node title]. – No Sssweat Oct 4 '17 at 7:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy