Target ID from a URL

Hi there,

Is there anyway I could get the current URL? Mainly I want to know what the target ID from the URL is within liquid, so I can create a working navigation bar that shows which item was selected using targets within the template. Is that somehow possible?

Hi @ronald_groot_RSF

are you referring to a navigation bar like this example?

This is an example of our annual accounts BE , where we are linking to different templates.

Or are you searching for a navigation bar that links to different places within the same template (more like an index)?

Thanks for your clarification.

Kr
Sofie

Hi Sofie,

Thanks for the quick response.

Yes, I’m looking for an index here, so no different templates.

Hi @ronald_groot_RSF

you can refer to a target in the template (reconciliation template) that you are working in

{::font size='xl'}Index{:/font}
{% linkto period.reconciliations.index target:"question_1" %}Question 1{% endlinkto %}
{% linkto period.reconciliations.index target:"question_2" %}Question 2{% endlinkto %}
{% linkto period.reconciliations.index target:"question_3" %}Question 3{% endlinkto %}

{::target id="question_1"}Question 1{:/target}
This is the first question
{::target id="question_2"}Question 2{:/target}
This is the second question
{::target id="question_3"}Question 3{:/target}
This is the third question

Is this what you were looking for? If not, can you elaborate the use case a little bit more?

Kind regards
Sofie

Hi Sofie,

Yes, this is how far I got. But want I want to do is highlight the question that is currently selected. When lining to a different template I’s use this:

{% if item.handle == current_reconciliation.handle %}
**{{ item.name }}**
{% else %}
{% linkto item %}{{ item.name }}{% endlinkto %}
{% endif %}

Do ideally, using your example above I’d be able to do the same thing:

{% if target == current_target %}
**{{ item.name }}**
{% else %}
{% linkto period.reconciliations.index target:"question_1" %}Question 1{% endlinkto %}
{% endif %}

But I have no code with which to do so

Hi @ronald_groot_RSF,

I understand what you are trying to achieve. Unfortunately it’s currently not possible to access the url of a template to see if it contains the target id. I will log this as a feature request.

Kind regards,
Kimberly

Hi @Kimberly,

yeah, I thought as much but figured it couldn’t hurt to ask anyway :wink: Thanks for logging my request!