liquideleventy

How to get an absolute URL with the slugify filter in Eleventy Liquid templates?


In an Eleventy site using Liquid templates I can usually get a full/absolute URL with the url filter like this {{'/books/' | url}}

When I am looping through data I need to use the slugify filter to convert that data into a usable URL like this: /books/{{book.title | slugify}}

That works, but I get a URL that is not absolute. How can I get both to happen? I have tried the following:

I can't seem to find any documentation on using multiple filters like this.


Solution

  • {{ '/books/' | url }}{{ book.title | slugify | url }}
    
    <a href="{{ '/books/' | url }}{{ book.title | slugify | url }}">{{ book.title }}</a>