0

I'm trying to build a block for tb_megamenu of a view of items of a certain content type. I want to use some JavaScript so that when the end user hovers over a title then associated content appears on the right hand side.

I've got the JavaScript/jQuery functionality working by attaching a library to the views display twig template and it works with a simple global text field using the correct IDs. However, it won't work with tokens because all ids will apply to all instances of the field content, so that hovering will show all related content.

Is there a way to separate the fields out like a delta field? I can build this in HTML ultimately but it wont be manageable by the end user ultimately.

Note: The tb_megamenu is irrelevant really. Just a view. Imagine a list of links coming from a field in a content type - Title1, Title2, Title3 - 3 pieces of content. I add another field to the view - Summary for example. I want to display the summary related to Title1 if I hover over Title1. And the summary for Title2 if I hover over Title2. My approach which I dont think can work was to hide the fields and to rewrite the output in a global text field using tokens. I add a javascript library to the view template so that I could use divs in the rewritten output.

  • 1
    Incredible. I ask a question that I want help answering and its voted down. 'Stay for the community'. I really dont understand this. Is the question not clear? Am I not allowed to not understand something? – tinamou_ed Jun 1 at 4:04
  • Didn't downvote. But I don't understand the question. Why don't you target classes for example? Did you try to add templates for the Views fields already? Did you try to add IDs through the Views interface already? What tb_megamenu? Basically I think you need to help us reproduce this issue. Many thanks – leymannx Jun 1 at 6:39
  • If I understand the question, you can create a twig template for this block and add your id, or you can use a contrib module like Block Class drupal.org/project/block_class – Mohamed Osama Gbril Jun 1 at 13:03
  • Ok thanks. The tb_megamenu is irrelevant really. Just a view. Imagine a list of links coming from a field in a content type - Title1, Title2, Title3 - 3 pieces of content. I add another field to the view - Summary for example. I want to display the summary related to Title1 if I hover over Title1. And the summary for Title2 if I hover over Title2. My approach which I dont think can work was to hide the fields and to rewrite the output in a global text field using tokens. I add a javascript library to the view template so that I could use divs in the rewritten output. – tinamou_ed Jun 1 at 14:20
  • Here is someone elses jsfiddle that represents kind of what I want to output in the view. jsfiddle.net/tkVZ4 – tinamou_ed Jun 1 at 14:20

Your Answer

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

Browse other questions tagged or ask your own question.