Jump to content

Creating dynamic URLs in Templates


inkredible

Recommended Posts

Posted

I want to build a dynamic URL inside of template, which looks similiar to this:

<a href='{url="app=botuserpanel&module=userpanel&controller=userpanel{{if $tab->area}}&area={$tab->area}{{endif}}"}'></a>

 

Because of my if expression it won't build the URL correctly, the result looks like:

<a href="{url="app=botuserpanel&module=userpanel&controller=userpanel&area=sessions"}"></a>

. Is there a way to build the URL correctly with my IF expression? For example is it possible to build the URL string upfront (but still inside of my template), pass that to {url=} so that it will work?

Posted

There's more than one way to handle this, but one solution would be

{{$url = \IPS\Http\Url::internal( components ... );}}
{{if $tab->area}}
	{{$url = $url->setQueryString( 'area', $tab->area );}}
{{endif}}

 

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...