I have a Search page created using the embedded filters and views. The page is working perfectly. Part of the results look like below:

https://imgur.com/a/yI1Zqik

The number showing on the top is the program ID. Upon clicking the 'Learn more' button, I want to redirect to the page which shows the details of the selected program. Not sure of which way i should start with the process. I need to design a Dynamic template and when clinking the 'Learn more' button of a specific program I should fill the template with data. Is there a way to do this? Any suggestion on where to start?! Thanks!

Comments

wombatbuddy’s picture

You can create the second view and set its url path like: /details.
This view will be display the detailed infor.
Add to this view the contextual filter, for filtering by program ID field.
Then in your first view rewrite the result of some field with the link like this: /details?program_id={{ 'field_program_id' }}

s_andy’s picture

Thanks! If I want to add additional blocks like 'Google maps' to the details page can I still use the same route? Also any best link to learn about contextual filters? Haven't used that before and I am unable to find an example similar to my needs.

wombatbuddy’s picture

I think that you can.
You'll find many tutorials, for instance, this one:
'Drupal 8 Site Building, Lesson 29: Contextual Filters'.

s_andy’s picture

Thanks a lot! Also the contextual filter should be added on 'Details' view right?

Will try this right away and post if I'm seeing any challenges.

s_andy’s picture

I tried this method. attaching the details view with contextual filter config here. Also attaching the code I have added to my primary view.

I am still not able to see the result of a specific program. It is showing me all the program names. Any help?!

Detail view screenshot: https://imgur.com/a/Z1kTsKa

Contextual filter screenshot: https://imgur.com/a/TJhv1cg

Results: https://imgur.com/a/kK3y1hF

My URL is: /details?program_id=field_program_id it's not taking in the field_program_id value :(

"Learn more" button code:  <a class="button js-form-submit form-submit btn-info btn" type="button" value="LEARN MORE" href=/details?program_id={{ 'field_program_id' }}>LEARN MORE</a>

Also in the link what is program_id field? is it the contextual filter field name?

wombatbuddy’s picture

1. You need to configure the contextual filter properly, see the screenshot: https://cdn1.imggmi.com/uploads/2020/1/24/6f7e39f1ba522fdc721a43224660a8...
2. 'program_id' is just a name of the query parameter (you are free to use another name).

wombatbuddy’s picture

Another way is to create the link like this: 

<a href="/details/{{ field_program_id }}">More details</a>

and configure the contextual filter like on this screenshot:
https://cdn1.imggmi.com/uploads/2020/1/24/af025899afff3ae8bebd72101faeac...