We are passing the full url of a page via the mbox but realised that it is also including the # fragment or parameters, we want to then use the url in our recommendations design, an example entity url is:
http://www.example.com/page1.html?adobe=QA
In our design we set:
<a href="$entity1.pageUrl">$entity1.name</a>
It outputs like this:
<a href="http://www.example.com/page1.html?adobe=QA">My Item</a>
but we really want it to out like:
<a href="http://www.example.com/page1.html">My Item</a>
Is there a way through Velocity Scripting to remove any parameters and # fragments so that only the raw url is left?
Solved! Go to Solution.
Well then you could put a script at the end of the template that looks something like the below example. You would have to put a class name on each of the A tags in order for it to loop through them. Might need to add some additional checking to prevent console errors but it should get you into the right ballpark:
<script>
var test = document.querySelectorAll('.CLASSNAME')
for (var i=0; i<test.length; i++){test[i]['href']=test[i]['href'].split('#')[0]}
</script>
There are some velocity helpers (substring, etc) though js would probably be a bit better.
Views
Replies
Total Likes
How are you getting data into recommendations? Using the entity.id params on the client side? Or the csv feed?
Getting those params out of the database would likely be the best route rather than trying to trim off in the template.
Thanks Eric, we are passing this information via the mbox (done via the DTM), as the moment we can't update the code to fix this issue and since it's on page load using the csv approach also doesn't work as that get overridden via the mbox call. I know it's not ideal to use velocity to fix this issue but the issue is currently stopping us launching to need a solution using that method if possible?
Views
Replies
Total Likes
Well then you could put a script at the end of the template that looks something like the below example. You would have to put a class name on each of the A tags in order for it to loop through them. Might need to add some additional checking to prevent console errors but it should get you into the right ballpark:
<script>
var test = document.querySelectorAll('.CLASSNAME')
for (var i=0; i<test.length; i++){test[i]['href']=test[i]['href'].split('#')[0]}
</script>
There are some velocity helpers (substring, etc) though js would probably be a bit better.
Views
Replies
Total Likes
Thanks, I'm going to try this; I'm also looking at creating a new field on the CSV too with just the raw url, then reference that instead of one being sent via the mbox.
Views
Replies
Total Likes
Views
Like
Replies
Views
Like
Replies