I have a slot displaying FAQs. When I click on one of the questions it should display the answer below the question within the same slot. I am not redirecting to a new page here onclick event.
Here a section of the html…
<div align=“left”>
<a href="#" >
Q. #field(“question”) ?
</a>
</div>
#if($answerValue != “0”)
<div > #field(“answer”)
</div>
#end
Also when I click on the same question again, the answer field should disappear.
Here is the binding I am using to achieve this
$answerValue = $rx.location.getFirstDefined($sys.item,‘rx:answer’, ‘0’)
I am not sure my approach is right. Can someone guide me through this issue?
This is a repost. I have rephrased my problem here
Here’s what I am trying to do…
I have a slot displaying FAQs. When I click on one of the questions it should display the answer below the question within the same slot. I am not redirecting to a new page here onclick event.
Also when I click on the same question again, the answer field should disappear.
I am not sure my approach is right. Can someone guide me through this issue?
Try moving the script tag from the page template to the global template, or select the “None” radio button on the page template in the section to determine which global template it uses.
Andrew is right, you need to move your JS reference to the Global Template.
The header code in a Snippet is only used when previewing the Snippet itself. If you are viewing published HTML or previewing a page including the Snippet, the header is stripped out during assembly. The header code in a Page Template is used the same way.
If you are using a Page Template intended for outputting FAQs, you might want to implement a Global Template specific to that Page Template and include the JS reference in that Global Template.
I am still facing a problem. When I insert only one snippet, clicking on the ‘question’ Link displays the ‘answer’ and then when I click again makes the ‘answer’ disappear.
But when I insert 2 or more snippets(each displays one question) no matter which ‘question’ link I click on, it displays the answer in the first snippet. I think I have a vague idea why this happens but I could not figure out a workaround.
I hope I have not created confusion around my issue.
Sounds like the issue is in the JavaScript and how it decides which block to expand. Does that work correctly in an HTML page not managed by Percussion CM System?