Download
We're evolving to serve you better! This current forum has transitioned to read-only mode. For new discussions, support, and engagement, we've moved to GitHub Discussions.

How to get current page url without “.”

  • #5602
    Avatar photo[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!

    #5628
    Avatar photo[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}}

    #5653
    Avatar photo[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!