Skip to content

Commit

Permalink
Handle website contacts dynamically
Browse files Browse the repository at this point in the history
This commits change the way contacts params are handled: instead of
declaring them statically, they are declared as an array of tables in
the TOML configuration file, then they are displayed in the two sections
(homepage and footer) of the website through the {{ range }} statement.

This makes handling multiple contacts params easier and avoids the
need of changing manually this two files:
- `layouts/partials/footer.html`;
- `exampleSite/content/homepage/contact.md`;

Signed-off-by: Filippo Fontana <[email protected]>
  • Loading branch information
filippofontana authored and zjedi committed Mar 10, 2024
1 parent 2d94f74 commit 69acce5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
14 changes: 11 additions & 3 deletions exampleSite/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ title = "Jane Doe - Nutrition Coach & Chef Consultant"
[params.meta]
keywords = "some, keywords, for, seo, you, know, google, duckduckgo, and, such"

[params.contact]
email = "[email protected]"
phone = "+49 1111 555555"
[[params.contacts]]
label = "phone"
value = "+49 1111 555555"
url = "tel: +49 1111 555555"
icon = "fa fa-phone"

[[params.contacts]]
label = "email"
value = "[email protected]"
url = "mailto: [email protected]"
icon = "fa fa-envelope"
4 changes: 1 addition & 3 deletions exampleSite/content/homepage/contact.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ weight: 4
header_menu: true
---

{{<icon class="fa fa-envelope">}}&nbsp;[{{<email>}}](mailto:{{<email>}})

{{<icon class="fa fa-phone">}}&nbsp;[{{<phone>}}](tel:{{<phone>}})
{{<contact_list>}}

Let us get in touch!
9 changes: 5 additions & 4 deletions layouts/partials/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
{{ end }}

{{ if ne .Site.Params.footer.showContactIcons false }}
{{ with .Site.Params.contact }}
<section class="icons">
<ol>
<li><a href="mailto:{{ .email }}" aria-label='{{ i18n "email" }}'><i class="fa fa-envelope"></i></a></li>
<li><a href="tel:{{ .phone }}" aria-label='{{ i18n "phone" }}'><i class="fa fa-phone"></i></a></li>
{{ range .Site.Params.contacts }}
<li>
<a href="{{ .url }}" aria-label='{{ i18n "{{ .label }}" }}'><i class="{{ .icon }}"></i></a>
</li>
{{ end }}
</ol>
</section>
{{ end }}
{{ end }}

{{ with .Site.Params.copyright }}
Expand Down
3 changes: 3 additions & 0 deletions layouts/shortcodes/contact_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{ range .Site.Params.contacts }}
<p><i class="{{ .icon}}"></i>&nbsp;<a href="{{ .url }}">{{ .value }}</a></p>
{{ end }}

0 comments on commit 69acce5

Please sign in to comment.