Velocity Scripting Help - Removing Parameters

frank-breen 20-03-2019

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: 

In our design we set:

<a href="$entity1.pageUrl">$</a>

It outputs like this:

<a href="">My Item</a>

but we really want it to out like:

<a href="">My Item</a>

Is there a way through Velocity Scripting to remove any parameters and # fragments so that only the raw url is left?

Accepted Solutions (1)

Accepted Solutions (1)

Eric_Vidana 21-03-2019

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:


var test = document.querySelectorAll('.CLASSNAME')

for (var i=0; i<test.length; i++){test[i]['href']=test[i]['href'].split('#')[0]}


There are some velocity helpers (substring, etc) though js would probably be a bit better.

Answers (3)

Answers (3)

Eric_Vidana 20-03-2019

How are you getting data into recommendations? Using the 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.

frank-breen 21-03-2019

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.

frank-breen 21-03-2019

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?