0

In D8, I am struggling to build a link in Views. I keep running into either a missing option or checkboxes ignored.

I have three fields pulled into views:

  1. Content: Title [hidden] .... token is {{ title }}
  2. Content: Resource Type [hidden] .... token is {{ field_resource_type }} Pulls values from Taxonomy
  3. Content: Link to Content .... token is {{ view_node }}

I want to rewrite the Content: Link to pass variables. So I'm outputting the URL as text

I essentially want: "{{ view_node }}?title={{ title }}&type={{ field_resource_type }}

I also want to replace the spaces with dashes, so my end result is: /resource/article-one-url?title=article-one-title&type=white-paper

But... if I override the output, and make my own URL, the system ignores if I check the box to Replace spaces with dashes

I do this by first checking "Output this field as a custom link," so that I can see and check the "Replace spaces with dashes" option.

I would try to rewrite the URL in the "Output this field as a custom link" section, but the field I thought was supposed to be there, is not.

UPDATE: I also tried this with a custom text field. Within the field settings I checked "Output this field as a custom link" and put the same tokens in, but this does the same thing. Spaces exist in the url.

  • Why do you need these query parameters when linking to content? – Joseph Sep 27 '19 at 1:31
  • Because they get pulled into hidden fields of an embedded Marketo form on the page these URLs would take the user to. They have to be passed in the URL. Using Post is not an option for me. – turpentyne Sep 27 '19 at 1:33
  • If you're on the content page already, you should have a reference to the current entity, or at least be in the context of it. If this embedded form is implemented in Drupal (i.e. a block), it should have access to this entity object from which you can extract this field data. You might want to elaborate more on how this embedded form is implemented. – Joseph Sep 27 '19 at 1:35
  • No.. in this case, that is not an option. I must pass via URL parameter. I'd rather not elaborate on how the form is working. I'm really just wanting how to modify the URL. – turpentyne Sep 27 '19 at 1:36
  • If it is not possible to configure the field handler to produce the output you want, you can still use Twig code. See for example twig.symfony.com/doc/2.x/filters/replace.html – 4k4 Sep 27 '19 at 6:29
1

The field Link to Content can only link to content lol, it doesn't seem you can override the link URL there (that is why there is no Link path field there, Views interface and features can be confusing at times, you have to know a bit of background to understand the less polished parts).

You should Exclude from display the Link to Content field, move the Title field down so it's the last field, and unhide it.

Then you will be able to contruct what you want using the Title field, using the Output this field as a custom link option.

The option Override the output of this field with custom text doesn't provide the option to Replace spaces with dashes.

Make sure that the Link to the Content in the Title field is not ticked, and the Formatter is set to Plain text to avoid clashing between different features when Drupal is constructing the output.

|improve this answer|||||

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.