nommensen
I'm new here

unique id in genric link output

Hello,

new to FS and need to know how to get a unique id in the html output of a link which is rendered via a generic link template and used in DOM-Editor and Linklist.

This works in a linklist, but is deprecated:

$CMS_SET(set_lt_id,#global.id.toString()+"_"+ #link.getAttributes().get("localId").toString())$

Thanks in advance

Thomas

0 Kudos
15 Replies

Thanks Holger,

but the editor can choose between internal and external links in a linklist. And he can use the links in the DOM component. So i have a mix from different links for which i need an ID in the anchor tag (to bind it to jquery). And you never know if a editor connects two links in the same component to the same target.

from other cms i kown they have an UID for each instance of a template. so i thought this must be the same with FS and "Verweisvorlagen". And the old implemantation guided me that way. But with the new generic links a lot of things have changed, e.g. most of the methods and attributes for the link class are deprecated without any substitute (or I'm to stupid to find it in the api ;-))

0 Kudos

Hello Thomas,

if you really just need an unique number, just use:

$CMS_VALUE(lt_text.hashCode())$

for the external link. [returns a hash code for the string of the url.

You can use this for internal links, too:

$CMS_VALUE(ref(lt_link).url.hashCode())$

[maybe you need a "toString()" here after .url, I didn't check it]

is this an adequate solution?

[This will work as long as nobody uses the same linktarget within the page. To make it safe for most user ideas, you can add a counter:

at the beginning of the page (for unique links within a page) or within the sourcecode of the global settings template (for unique links over the whole channel)

$CMS_SET(myLinkCounter,0)$

And before the output of any link:

$CMS_SET(myLinkCounter,myLinkCounter+1)$

and then:

$CMS_VALUE(myLinkCounter.toString() + "_" + lt_text.hashCode().toString())$

Best regards from Dortmund,

  Holger

0 Kudos

Hi Holger,

the counter solution is what i do at the moment and i combine it with the section.id, but i thought of that more as workaround then as best pratice. As christoph stated contentId should work (but dos not at the monet), so i still hope 😉

regards

Thomas

0 Kudos

contentId? You used "localId" in your first post. I assumed that this was a component in your generic link form, but it isn't.

Btw. what's the use case for these unique ids? Do you need to reference them within a javascript?

0 Kudos

What id need is a UID for the id attribute of an any anchor tag to bind it to jquery.

so, yes i need it for javascript.

On my way to find a solution i looked for everything in the api with the postfix "Id".

from other cms i kown they have an UID for each instance of a template. so i thought this must be the same with FS and "Verweisvorlagen". "contentId" in the answer to holger was my mistake. As i stated above, I'm new to FS so maybe i looked in the wrong direction. I need a uid for the anchor where ever i use a generic link template (for internal and external use and independend if the template is used in DOM or any other component). At the moment i use  counters and combine them with sectionIds and a static prefix. This works, but i  wonder if this should be best pratice.

i hope i could clearify the task this time.

0 Kudos

Objects like pages, pagerefs, sections, data records etc. do have unique ids that can be used in such situations. Generic links don't have that as well as other more complex input components. Our default way to handle this is to assign a CSS class to this elements and use a javascript library to generate unique ids. Most javascript libraries support that out of the box.

0 Kudos