2012-03-23 77 views
16

我剛剛開始使用Github來託管我的博客(使用Jekyll和Liquid)。但是,我有an issue which I can't currently fix。如果我能夠檢測到用戶正在訪問哪個「頁面」或「網址」,該問題可能會被黑客入侵/解決。液體標記檢測當前頁面的URL?

喜歡的東西:

{% if user_is_currently_at_this_url %} 
    {{ display something }} 
{% else %} 
    {{ display something else }} 
{% endif %} 

這可能嗎?有沒有其他解決此問題的方法?

回答

29

page.url是當前頁面的URL,沒有主機(例如/index.html),如Page Variables中所述。所以,在這種情況下:

{% if page.url == "/index.html" %} 
    something 
{% else %} 
    other thing 
{% endif %} 

(不過,我不認爲你需要這個更多,你的其他問題可能是解決:))。

+0

是對已經被解決我的問題,但還是謝謝你爲此:) – n0pe 2012-03-23 03:26:35

+0

'page.path'可能會更好,如https://github.com/jekyll/jekyll-help/issues/5#issuecomment-39033862所示 – koppor 2016-01-26 19:39:27

+2

這不適用於Github頁面上的404重定向:( – 2016-03-29 22:40:46