How to get current page url without “.”
-
April 12, 2021 at 11:29 am #5602
[anonymous]
Hi,
I need the current pages url address, as i tried, {{url}} will return the address form like “./abc.html“.
However, I need something return “/abc.html” with current pages, which is not “.” before the “/“.
How to achieve this? also do not return http/https or website domain, just pages url only
thanks!
April 17, 2021 at 5:28 pm #5628
[anonymous]
Hi,
It seems that you are using relative URLs, that’s why you get that dot at the beginning.
The only solution is to create a custom helper which will get url as an argument and will remove the dot. Example custom helpers are described here: https://getpublii.com/dev/tags/custom-helpers/
you will need something like:
let themeHelpers = { removeDot: function(url) { if (url[0] === '.') { return url.substr(1); } return url; } }; module.exports = themeHelpers;and then you can use:
{{removeDot url}}
April 20, 2021 at 11:48 am #5653
[anonymous]
Tomasz Dziuda wrote:Hi,
It seems that you are using relative URLs, that’s why you get that dot at the beginning.
The only solution is to create a custom helper which will get url as an argument and will remove the dot. Example custom helpers are described here: https://getpublii.com/dev/tags/custom-helpers/
you will need something like:
<span class=”enlighter-text”>let themeHelpers = </span><span class=”enlighter-g1″>{</span><span class=”enlighter-text”> removeDot: </span><span class=”enlighter-k1″>function</span><span class=”enlighter-g1″>(</span><span class=”enlighter-text”>url</span><span class=”enlighter-g1″>)</span> <span class=”enlighter-g1″>{</span><span class=”enlighter-k1″>if</span> <span class=”enlighter-g1″>(</span><span class=”enlighter-text”>url</span><span class=”enlighter-g1″>[</span><span class=”enlighter-n1″>0</span><span class=”enlighter-g1″>]</span><span class=”enlighter-text”> === </span><span class=”enlighter-s0″>’.'</span><span class=”enlighter-g1″>)</span> <span class=”enlighter-g1″>{</span><span class=”enlighter-k1″>return</span><span class=”enlighter-text”> url.</span><span class=”enlighter-m3″>substr</span><span class=”enlighter-g1″>(</span><span class=”enlighter-n1″>1</span><span class=”enlighter-g1″>)</span><span class=”enlighter-text”>;</span><span class=”enlighter-g1″>}</span><span class=”enlighter-k1″>return</span><span class=”enlighter-text”> url;</span><span class=”enlighter-g1″>}</span><span class=”enlighter-g1″>}</span><span class=”enlighter-text”>;</span><span class=”enlighter-text”>module.</span><span class=”enlighter-m3″>exports</span><span class=”enlighter-text”> = themeHelpers;</span>let themeHelpers = { removeDot: function(url) { if (url[0] === ‘.’) { return url.substr(1); } return url; } }; module.exports = themeHelpers;let themeHelpers = { removeDot: function(url) { if (url[0] === ‘.’) { return url.substr(1); } return url; } }; module.exports = themeHelpers; and then you can use:
{{removeDot url}}
Hi,
Thank you for your reply.
I have tried your method. it would take ” PUBLII_RELATIVE_URL_BASE#/xxx.html ” instead of “.”.
and how to achive this if the url is not relative?
Thank you!