I have tried with {{url}}
but it is giving the URL
of the scoped block. For example: when I am using the {{url}}
in
{{#foreach tags}}
<a href="{{url}}">Tag name</a>
{{/foreach}}
it is giving the URL
of that tag, not the current page URL
.
Can anyone suggest how can I get it?
Hey there, this should be {{@site.url}}
.
More info here: Ghost Handlebars Theme Helpers: @site
Does that give the current URL as in, for example, https://example.com/how-to-install-ghost/
?
You can’t get current page URL with {{@site.url}}.
I have done it through window.location.href
If you need to move to a parent scope, you can use ../
e.g:
{{#foreach tags}}
<span> You are currently on {{../url}}</span>
<a href="{{url}}">Tag name</a>
{{/foreach}}
Please, if you don’t mind- how do I get the current URL in a <a href link?
It depends on the context you’re in, but this should work:
<a href="{{url absolute="true"}}">Current Page</a>
1 Like
Ah totally missed the current
part, my bad.
Ok, so I should be able to use it like this if I’m looking for a way to use the current URL as the subject line?
<a href="mailto:email@example.com?subject={{url absolute="true"}}&body=Hello" target="_blank"></a>
1 Like
Please, could you provide an example of how to use the current post title where “How to install Ghost
” is the post title of example.com
as in https:/example.com/how-to-install-ghost/
as the subject line?
I’ve been trying to get that to work. Should I use {{title}}
? If so, how?
You’ll want to use the encode helper for both of these:
1 Like
Yes, so I have been told. Can you please provide an example?
Can you explain what you are expecting to see vs. What you actually see when you use the example provided?
I want to add a global link to all posts that uses the post title as the subject. Example: How to Install Ghost
is the post title. The URL becomes https://example.com/how-to-install-ghost/
When clicking the link, the subject of the email should be How to Install Ghost
How does that fit into the <a href
HTML? Like this: <a href="mailto:contact@example.com?subject{{what do I put here to get the post title?}}" target="_blank">Email Link Text</a>
The reason I’m really confused is the usage is documented in the encode helper:
href="https://twitter.com/share?text={{encode title}}&url={{url absolute='true'}}"
Of course, thats’s telling you how to share to twitter, but you can adapt it to work for mailto links
For the first question, most Ghost themes have some variation of that functionality:
<h2><a href="{{url}}">{{title}}</a></h2>
ok, so I would use ?subject={{encode title}}
That seems like it should work
Hey!
I just wanted to say thanks for “putting up with me” and for your help and support. I appreciate it. I got my global link to work and now - any user / visitor can report a function.
2 Likes