GET parameter with array

Hi there,

Hopefully somebody can help me out! I’m trying to retrieve a GET variable with an array, but I can’t figure out how to do this. The query string is something like domain.com/projects?project_type%5B%5D=name&project_type%5B%5D=name2

I tried things like request.query_dict.project_type and request.query_dict[‘project_type[]’], but I only seem to retrieve the first GET variable.

Could somebody help me out how to do this in HubL? Thanks for your help!

@RoFiks - I may have the wrong interpreation of your question here, but it seems like you may be trying to retrieve a query string value that represents a multi-value property. You definitley can’t do this by repeating the query string. Have you tried using the formula of passing a composite string that looks like “valuea;valueb;valuec” - that is using semicolons to seperate out the individual values. This is often how such properties are represented in the UI.

Steve

Hi Steve,

Thanks for helping! I thought it was possible to retrieve multiple values also with creating an array, but isn’t this the case?

Without the urlencode it would look like: domain.com/projects?project_type[]=name&project_type[]=name2, which would give a GET variable with an array(name, name2).
Your solution to create a string instead of an array would definitily work, thanks! I was just wondering if it would be possible to retrieve an array from a GET variable with HubL as well :slightly_smiling_face:

@RoFiks With some hubl-magic you can do this.

I don’t understand why this isn’t supported out of the box, but here you go:

$project_types = request.query|split('&')|select('containing', 'project_type' )|join('&')|replace('project_type=', '')|split('&')