How to implement a Custom Counter

Can anyone tell me how I can add a custom counter to each result item without an ordered list?
What I have is a add to favourites but some names have a identical data-id but if I add a counter teach then I get a unique number.

I have this at the top of my search page <#assign count = 0>
This is what I’m trying to do
<a href="# "data-courseid="${s.result.metaData["A"]!?replace("|", ", ")}_ <#assign count = count + 1>"

this throws an error - completely breaks the page so can someone show me how this is done?

Thanks in advance
N

Could use just use the rank and adjust as necessary?

Thanks Ian, I’ve just been given the task of looking after search so I’m a tad rusty plus I updated my question to show the code. Can you give me an example code or point me to the help section on how to use the rank?

Thanks
N

Hi Nicky,

Try this?

<a href="#" data-courseid="${s.result.metaData["A"]!?replace("|", ", ")}_${s.result.rank!}">

Otherwise your original code wasn’t too far off, but instead of just assigning a new value to the count, you’d also need to print the value where you want it:

<#assign count = count + 1>
<a href="#" data-courseid="${s.result.metaData["A"]!?replace("|", ", ")}_${count!}">

Hey Ian, using your options definitely worked so thank you. I am interested however to get my almost original code to work as well however using this still breaks the page, any ideas?

<#assign count = count + 1> or  <#assign count = count++>?
<a href="#" data-courseid="${s.result.metaData["A"]!?replace("|", ", ")}_${count!}">

Does it give you a visible error? Or what does the output HTML look like (view source, not just from the elements panel in dev tools)?

Otherwise I’m not sure, it’s a bit tricky to debug without any further information.

It may have been because of the results is a seperate “results.ftl” i.e using
<#import "results.ftl" as Result/>
So when I moved the assign code to the results I didn’t get an error but I now am getting a number but its not incrementing - they’re all just have a _1
data-courseid="HLB102_1" etc

Thanks
N