Hello, and sorry if I’m bothering you. I tried to read other threads on this forum and on stackoverflow, but I didn’t manage to find a solution for this problem.
What I’d like to do is to pick a phone number in a string format, like this:
(+39) 347 1234567
And use it to create a phone link as this:
<a href="tel:+393471234567">(+39) 347 1234567</a>
The problem is that I need to do this job multiple times. Instead of having to copy & paste this code many times I’d rather prefer to create a sort of “function” that I could call anywhere in my template.
As I tried to build this sort of “function”, I have create a partial file named phone.html that contains this very basic code:
1) Use := to declare a variable, setting the initial value. Use = to change the value.
2) When calling a partial use the partial statement, not partials.
3) As @pointyfar described, the only thing you need to pass to your partial is the phone number.
{{ partial "phone.html" .Site.Params.phone }}
4) When you fix #1, #2, and #3, the result will still be wrong because the plus sign within the href attribute will be encoded; this is incorrect. You’ll need to use the safeHTMLAttr function.
This is the cleanest partial that I could come up with: