Skip to content

Get page.url from pagination item? #1767

Answered by tannerdolby
iwm-donath asked this question in Q&A
Discussion options

You must be logged in to vote

You can see in worry.njk that I use data-id="{{ quiz.title }}" as an identifier for JavaScript. It works, but feels a bit dirty. It could happen that two questions have the same title. Therefore I would like to have an unique identifier.

I wrote a longer comment to your reply here. A shorter and more succinct answer is:

Inside worry.njk replace

<main {% if not quiz.answer_page %}data-id="{{ quiz.title }}"{% endif %}>

with:

<main data-id="{{ page.url }}">

So then each <main> element has a unique data-id custom attribute:

<main data-id="/quiz/this-is-what-the-region-cares-about/1/">
...
<main data-id="/quiz/this-is-what-the-region-cares-about/9/> <!-- Last page -->

This way, without the if

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
2 replies
@iwm-donath
Comment options

@tannerdolby
Comment options

Comment options

You must be logged in to vote
4 replies
@iwm-donath
Comment options

@tannerdolby
Comment options

@iwm-donath
Comment options

@tannerdolby
Comment options

Answer selected by iwm-donath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants