How to retrieve parameters by route - Node JS

I have a route like this
image

I have a Content Page like this

I don’t know how to recover the route parameter

@Teodor @patrick ?

Check:

Hello @Teodor I had seen the post more does not help much, in my case I’m not passing the wrong parameter

I would like help with that, can anyone help?

You know as a friend? @JonL

I guess you could use ejs template tag and retrieve the parameter <% $_PARAM["parameter_name"] %> or <% $_PARAM.parameter_name %>

    <% 'Scriptlet' tag, for control-flow, no output
    <%_ ‘Whitespace Slurping’ Scriptlet tag, strips all whitespace before it
    <%= Outputs the value into the template (HTML escaped)
    <%- Outputs the unescaped value into the template
    <%# Comment tag, no execution, no output
    <%% Outputs a literal '<%'
    %> Plain ending tag
    -%> Trim-mode ('newline slurp') tag, trims following newline
    _%> ‘Whitespace Slurping’ ending tag, removes all whitespace after it

1 Like

Thanks I’ll try

Where exactly do you want to retrieve the parameter, on client or server? @JonL already giving you hints on getting it on the server using ejs template, on the client it should be available as query property query.token.

From what I see in your movie I think you are looking for the client-side solution, you added it as a query property but it wasn’t pickable. If the problem is just that it wasn’t pickable then probably it is a bug in the data picker and @George could have a look at it.

1 Like

I would like to retrieve the query property

I’m passing a parameter via url called token I would like to retrieve this parameter to make a query on Server Connect

for this the natural process is to define a query parameter

Then select Server Connect

After that, I have no way to select the token I created

Am I doing something wrong because no one is talking about it?

Adriano, what if you just enter it manually?

{{query.token}}

Returns nothing :pensive:

I believe parameters on nodejs model are not retrievable from App Connect in partials. This has going on for some time.

The only way right now is to retrieve them when the ejs is parsed on server as I explained previously. Depending on what you are trying to achieve this could be enough.

Strange that if I create a view and not a partial I can recover, I will make a video showing

Look this

but how can we solve this big problem? also with vers. 3.7.2 doesn’t work, can anyone point out a beginner solution? thanks

1 Like

Hey @Mark72it

I created a dirty little hack to solve this.

If you don’t have one yet create a custom.js file in public/js

Screenshot 2021-02-08 at 21.46.02

Call it in your layout file:

Drop this code into the custom.js file:

function getparams(mapto, pos) {
    var inpath = window.location.pathname;
    var inarr = inpath.split("/");
    var outval = inarr[pos];
    dmx.app.data.content[mapto].value = outval;
}

In your router settings setup you route. (it actually doesn’t matter what you call the param, it is about the structure:

Screenshot 2021-02-08 at 21.52.39

in the view you want to retrieve this param or params create the variable or variables you want to assign the params to:

Create a flow that auto loads and call the getparams(mapto, pos) function.
mapto = the created variable
pos is the position of the param
eg /account/paramvalue = /1/2

if you have for example /account/2345/678
create two variables and then run the function twice with the the correct values and positions for each url param.

Make sure you have the flow set to Auto Run

Your param(s) are now mapped to your set variables and you can use them anywhere in your code.

This is a much easier solution in my opinion.
You can do something like

<dmx-value id="var1" dmx-bind:value="<%= $_PARAM.parameter_name %>"></dmx-value>
<!-- in your example -->
<dmx-value id="linkcode" dmx-bind:value="<%= $_PARAM.linkedcode %>"></dmx-value>
1 Like