Skip to content

Commit

Permalink
Markup - Added url function (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
WebVPF authored Apr 12, 2024
1 parent ff96a6f commit 5703f16
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
51 changes: 51 additions & 0 deletions markup/functions/url.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# url_*()

## url()

The `url()` function generates a fully qualified URL to the given path.

```twig
{{ url('blog') }}
{# https://site.com/blog #}
```

You can specify a variable as a function parameter:

```twig
{{ url(category.slug) }}
{# https://site.com/slug-value #}
```

In function parameters you can use concatenation:

```twig
{{ url('blog/post/' ~ post.id) }}
{# https://site.com/blog/post/123 #}
```

### Base URL

You can get the base url like this:

```twig
{{ url('/') }}
{# https://site.com/ #}
```

## url_current()

The `url_current()` function generates a fully qualified URL to the current path. Syntax:

```twig
{{ url_current() }}
```

An example of generating a canonical link using the `url_current()` function and the `|lower` Twig filter:

```twig
<link rel="canonical" href="{{ url_current()|lower }}" />
```
1 change: 1 addition & 0 deletions markup/toc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,4 @@ sections:
functions/form: "form_*()"
functions/html: "html()"
functions/dump: "dump()"
functions/url: "url_*()"

0 comments on commit 5703f16

Please sign in to comment.