Sign in

How to get current page url without “.”

  • This topic has 2 replies, 2 voices, and was last updated 7 months, 3 weeks ago by .
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #5602
    cineray

    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
    Tomasz Dziuda

    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}}

    --
    Do you appreciate the support you've received today? If so, consider donating to the Publii team by clicking here; we'll be sure to use your donation to make Publii even better!

    #5653
    cineray

    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!

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.