Dynamic values in custom link

Avatar

Avatar
Level 1
dustinwallace
Level 1

Likes

0 likes

Total Posts

1 post

Correct reply

0 solutions
View profile

Avatar
Level 1
dustinwallace
Level 1

Likes

0 likes

Total Posts

1 post

Correct reply

0 solutions
View profile
dustinwallace
Level 1

15-02-2018

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?

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Contributor
MVP
joshd7227840
MVP

Likes

275 likes

Total Posts

241 posts

Correct reply

70 solutions
Top badges earned
Contributor
Give Back 10
Give Back 5
Give Back 3
Give Back
View profile

Avatar
Contributor
MVP
joshd7227840
MVP

Likes

275 likes

Total Posts

241 posts

Correct reply

70 solutions
Top badges earned
Contributor
Give Back 10
Give Back 5
Give Back 3
Give Back
View profile
joshd7227840
MVP

15-02-2018

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.

Answers (0)