helpers /  URL

URL

URL helpers are node.js url utilities for URL resolution and parsing. As with node.js:

{{urlParse}}

Take a URL string, and return an object.

Params

url

Type: String Default: undefined

The URL to parse.

output format

Type: String Default: json (options: yaml or json)

Template:

{{urlParse "http://example.com/one"}}

Renders to:

{
  "protocol ": "http:" ,
  "slashes ": true ,
  "auth ": null ,
  "host ": "example.com" ,
  "port ": null ,
  "hostname ": "example.com" ,
  "hash ": null ,
  "search ": null ,
  "query ": null ,
  "pathname ": "/one" ,
  "path ": "/one" ,
  "href ": "http://example.com/one" 
 }

Or with yaml as the second param:

{{urlParse "http://foo.com/bar/baz?key=value" "yaml"}}

Renders to:

protocol: "http:"
slashes: true
auth: null
host: "foo.com"
port: null
hostname: "foo.com"
hash: null
search: "?key=value"
query: "key=value"
pathname: "/bar/baz"
path: "/bar/baz?key=value"
href: "http://foo.com/bar/baz?key=value"
parse:
format:
resolve:
resolveObject:
parseHost:

{{urlResolve}}

Take a base URL, and a href URL, and resolve them as a browser would for an anchor tag.


Template:

{{urlResolve url href}}

Example:

<a href="{{urlResolve "http://example.com/one" "/two"}}"></a>

Renders to:

<a href="http://example.com/two"></a>

See the template for this page →

Find an error? Let us know →