Expand my Community achievements bar.

Help shape the future of AI assistance by participating in this quick card sorting activity. Your input will help create a more effective system that better serves your needs and those of your colleagues.
SOLVED

Dynamic values in custom link

Avatar

Level 1

I am trying to populate the value from the data-id attribute in the link clicked into the custom link, but it just shows %this.data-id% in the actual text in the pev2 value instead of replacing it with the value itself. Are not all dynamic references available in the Custom Link field?

1 Accepted Solution

Avatar

Correct answer by
Level 9

data attributes are special attributes that are found within the dataset object of an element.

So for example, if you have this link:

<a href="somepage.html" data-id="some id">some page</a>

(with pure javascript) you can get the value like so:

var a = document.querySelector('a');

console.log ( a.dataset.id ); // output: "some id"

Alternatively, you can use the elem.getAttribute() method, like so:

var a = document.querySelector('a');

console.log ( a.getAttribute('data-id') ); // output: "some id"

DTM's percent syntax does not let you do the former; it will only let you reference %this.foo% properties that are direct, top level properties of the element.  However, DTM does let you use getAttribute, so you can do this:

%this.getAttribute(data-id)%

Note: Unlike the pure javascript example above, for DTM's percent syntax, you should NOT wrap data-id in quotes.

View solution in original post

1 Reply

Avatar

Correct answer by
Level 9

data attributes are special attributes that are found within the dataset object of an element.

So for example, if you have this link:

<a href="somepage.html" data-id="some id">some page</a>

(with pure javascript) you can get the value like so:

var a = document.querySelector('a');

console.log ( a.dataset.id ); // output: "some id"

Alternatively, you can use the elem.getAttribute() method, like so:

var a = document.querySelector('a');

console.log ( a.getAttribute('data-id') ); // output: "some id"

DTM's percent syntax does not let you do the former; it will only let you reference %this.foo% properties that are direct, top level properties of the element.  However, DTM does let you use getAttribute, so you can do this:

%this.getAttribute(data-id)%

Note: Unlike the pure javascript example above, for DTM's percent syntax, you should NOT wrap data-id in quotes.