Lektor: url filter with absolute URLs

Created on 18 Oct 2016  路  3Comments  路  Source: lektor/lektor

Hi,

There seems to be an issue with the 'url' template filter :

<a href="{{ 'http://google.fr/' | url }}">Google</a>
will generate

http://localhost:5000/services/register/http:/google.fr

(where of course http://localhost:5000/services/register/ is my source page)

Maybe i've done something wrong ?

using Lektor 2.3

nice-to-have

Most helpful comment

Adding a +1 to this...having the url filter be agnostic to relative and absolute paths is nice for when an instance of a data model can have a more_info_url attribute that could point to either.

All 3 comments

The filter is for generating relative links.. you wouldn't use it for an external link so just <a href="http://google.fr">Google</a> is fine.

my real code is {{ this.url | url}} where url is a string field of my model ; which can either be a relative path to a page (like /company/about-us or products) but also can be an external URL like http://google.fr as stated in my example.

It just works as expected with a 鈥渓ocal" URL but just doesn鈥檛 work with an external one.

We could imagine a fix in the url filter with a regex detecting <scheme>:// at start of filtered URL.

Adding a +1 to this...having the url filter be agnostic to relative and absolute paths is nice for when an instance of a data model can have a more_info_url attribute that could point to either.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ajdavis picture ajdavis  路  9Comments

item4 picture item4  路  3Comments

geekpete picture geekpete  路  7Comments

davidferguson picture davidferguson  路  4Comments

yagebu picture yagebu  路  5Comments