Question

I need to form a link with some parameters in it like this:

<a href="[[~[[*id]]? &sorting=`Data.price`]]">

and then I want to get the parameters in my getPage snippet like this:

[[!getPage:default=`Ничего не найдено`?
    &element=`msProducts`
    &parents=`[[*id]]`
    &sortby=`[[*sorting]]`
    &sortdir=`ASC`
]]

How to accomplish this task properly? How to send and then get user's parameters?

Was it helpful?

Solution

Use setPlaceholders extra - https://github.com/oo12/setPlaceholders

[[!setPlaceholders? &ph=`sorting == get.sorting`]]

and then use [[+sorting]] it in your getPage construction

[[!getPage:default=`Ничего не найдено`?
    &element=`msProducts`
    &parents=`[[*id]]`
    &sortby=`[[+sorting]]`
    &sortdir=`ASC`
]]

OTHER TIPS

You can just loop through the _get variables in a snippet and set them all yourself, that way you don't have to specify which placeholder you are looking for with an extra snippet call each time and it gives you the opportunity to either sanitize your variables or do any extra processing.

$placeholderArray = array();

foreach ($_GET as $key => $value) { 

    $placeholderArray[$key] = $value;

}

$modx->setPlaceholders(array($placeholderArray));

return;

UPDATE

First, your link is wrong:

<a href="[[~[[*id]]? &sorting=`Data.price`]]">

should look like:

<a href="[[~[[*id]]]]?sorting=Data.price">

if you want to add more parameters or 'data.price' is a modx placeholder:

<a href="[[~[[*id]]]]?sorting=[[+Data.price]]&value2=[[+data.number]]">

I strongly suggest you read the modx developer documentation, all this is covered there: http://rtfm.modx.com/revolution/2.x/developing-in-modx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top