I want to understand how url
helper works. For example, in my template I have:
<a href="{{url "Pages.IndexPages" ???}}">my super url</a>
and in controller:
func (c Pages) IndexPages() revel.Result {
...
}
I need url like
http://localhost:9000/pages?page=1
I don't want to write:
func (c Pages) IndexPages(page int) revel.Result {
because I want to check if the controller contains the param page
.
How to add my template var to c.Params.Query
with the url
helper?
Revel url helper code in template.go
// Return a url capable of invoking a given controller method:
// "Application.ShowApp 123" => "/app/123"
func ReverseUrl(args ...interface{}) (template.URL, error) {
We need to update the manual with information about this template function, but you can see in the link and code above how it's intended to be used. You pass it a controller and action with parameters and it creates a template.URL
object with the matching route.
It seems you're not interested in how the url
helper works (though that's what you asked). You want to know how to pass the page
variable to the template? In your controller you need to pass page
via c.RenderArgs["page"] = page
. Then you can reference it in your template: <a href="{{url "Pages.IndexPages" .page}}">my super url</a>
Revel Template Doc.
As you noted, you can manually get the value for page
with page := c.Params.Query.Get("page")
if you don't want to use the parameter binding feature.