Ad

Using Array Variables In Page Filter

- 1 answer

This is the code

<a target="_blank" rel="nofollow noreferrer" target="_blank" rel="nofollow noreferrer" href="{{ 'questions' | page({Filter[search] : 1}) }}">{{category.name}}</a>

It should generate an URL like

http://localhost/vos-questions?Filter[search]=1&Filter[categories]=3&Filter[sort]=published_at+desc

but is not working! if I try to use 'Filter[search]' : 1 instead, the URL is generated but without the Filter params.

The destination page ('questions') is defined with a :page param, the Filter params are not defined.

title = "questions"
url = "/vos-questions/:page?"

What am I doing wrong ?

Ad

Answer

hmm it will not work

your url is like this url = "/vos-questions/:page?" so page must be the argument and it will be consider like this

/vos-questions/test => now in code `page` param's value will be `test`

if you really need that url then there is better solution.

// question page 
title = "questions"
url = "/vos-questions" <- we remove param here as we pass it manually


// now html code
<a target="_blank" rel="nofollow noreferrer" target="_blank" rel="nofollow noreferrer" href="{{'questions'|page }}?Filter[search]=1&Filter[categories]=3&
                    Filter[sort]=published_at+desc">{{category.name}}</a>

it should work as expected it will generate url like this

http://localhost/vos-questions/?Filter[search]=1&Filter[categories]=3&Filter[sort]=published_at+desc

and if you want to pass dynamic values you can also do like this

// suppose $search = 2 in code and $cat = 30

<a target="_blank" rel="nofollow noreferrer" target="_blank" rel="nofollow noreferrer" href="{{'questions'|page }}?Filter[search]={{ search }}
                          &Filter[categories]={{ cat }}
                    &Filter[sort]=published_at+desc">{{category.name}}</a>

so generated url will be

http://localhost/vos-questions/?Filter[search]=2&Filter[categories]=30&Filter[sort]=published_at+desc

now in code you can get this values using Input

https://octobercms.com/docs/services/request-input

$filter = \Input::get('Filter');
echo $filter['categories']; // => 30

if any doubts please comment.

Ad
source: stackoverflow.com
Ad