在页面过滤器中使用数组变量

时间:2018-09-27 18:50:04

标签: twig octobercms

这是代码

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

它应生成一个

之类的URL。
  

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

但不起作用!如果我尝试改用'Filter[search]' : 1,则会生成URL,但没有Filter参数。

目标页面(“ questions”)使用:page参数定义,未定义过滤器参数。

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

我在做什么错了?

1 个答案:

答案 0 :(得分:1)

嗯,它不起作用

您的网址是这样的<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"> <link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css"> <script src="https://code.jquery.com/jquery-1.11.2.min.js"></script> <script> $(document).on('mobileinit', function () { function showme(e, ui){ var activePage = $(":mobile-pagecontainer").pagecontainer("getActivePage").prop("id"); $("#events").append("Event: "+e.type+" raised from: "+(activePage ? activePage : 'landing')+"<br>"); if(activePage) { $("#events").append("Active Page: "+activePage+"<br>"); } if(e.target){ if(e.target.id) $("#events").append("Target Page: "+e.target.id+"<br>") } } $(document).on("pagecreate", function(e, ui) { showme(e, ui); }); }); </script> <script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> </head> <body> <div data-role="page" id="page-1"> <div data-role="header"><h1>Page 1</h1> <a href="#page-2" class="ui-btn ui-corner-all ui-btn-inline ui-mini">Go to Page 2</a> </div> <div role="main" class="ui-content"> <div id="events"> </div> <hr> Click "Go to page 2" </div> </div> <div data-role="page" id="page-2"> <div data-role="header"><h1>Page 2</h1> <a href="#page-1" class="ui-btn ui-corner-all ui-btn-inline ui-mini">Back to Page 1</a> </div> <div role="main" class="ui-content"> Page 2 has been created - Click back </div> </div> </body> </html>,因此url = "/vos-questions/:page?"必须是自变量,它将被认为是这样

page

如果您确实需要该网址,那么有更好的解决方案。

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

它应该按预期运行,它将生成这样的

  

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

如果您要传递动态值,也可以这样做

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


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

因此生成的网址将是

  

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

现在在代码中,您可以使用// suppose $search = 2 in code and $cat = 30 <a href="{{'questions'|page }}?Filter[search]={{ search }} &Filter[categories]={{ cat }} &Filter[sort]=published_at+desc">{{category.name}}</a>

获取此值

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

Input

如有任何疑问,请发表评论。