Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new global variable hide #817

Merged
merged 5 commits into from
Aug 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
+++
fragment = "config"

[[config]]
type = "js"
html = """<script>
document.querySelector("#content .title-container h2").style.color = "red";
</script>"""
+++
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
+++
fragment = "content"
weight = 110
title = "If you're seeing this, hide and fallthrough don't work"
+++
4 changes: 4 additions & 0 deletions exampleSite/content/dev/fragment-fallthrough/_index/config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
+++
fragment = "config"
hide = true
+++
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
+++
fragment = "content"
weight = 100
title = "Content fragment from Page"
title = "Content fragment from Page, this text should be black"
+++

This is loaded from the page, overriding the globals of current section. Seems
Expand Down
6 changes: 6 additions & 0 deletions exampleSite/content/dev/fragment-fallthrough/_index/hidden.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
+++
fragment = "content"
weight = 110
title = "If you're seeing this, hide doesn't work"
hide = true
+++
2 changes: 2 additions & 0 deletions exampleSite/content/docs/fragments/content.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ All fragments within this directory are rendered on all pages by default.
To overwrite a global fragment create a per page fragment with the same filename.
This would overwrite the global one.

In order to hide a global fragment in a specific page or section, you can use the [`hide` global variable]({{< ref "global-variables">}}/#hide).

Aside from the `content/_global/` directory, you can create `_global/` directory in any section's directory (`content/[section]/_global/`).
Each section can have global fragments and if there are multiple fragments with the same name, the fragment closest to the page would override the others.

Expand Down
12 changes: 12 additions & 0 deletions exampleSite/content/docs/global-variables/content.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,15 @@ Action/clickable URL of the image or the icon.
*type: string*

If `asset.image` is set, `text` will be used as alternative text (alt-text) of the image.

#### disable
*type: boolean*

If set to `true`, Syna will not register the fragment. This is useful for drafting fragments.

**NOTE:** `disable` doesn't register the fragment at all. This means you can not remove a global fragment in a specific page by a duplicate disabled fragment. In order to hide a global fragment in a page, use [`hide`](#hide).

#### hide
*type: boolean*

If set to `true`, Syna will not call the fragment and will hide it. Useful for hiding a global fragment in the page. For more information, please checkout [global fragments]({{< ref "docs/fragments">}}/#global-fragments).
2 changes: 1 addition & 1 deletion layouts/partials/helpers/fragments-renderer.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{{- range sort ($page_scratch.Get "page_fragments" | default slice) "Params.weight" -}}
{{/* If a fragment contains a slot variable in it's frontmatter it should not
be rendered on the page. It would be later handled by the slot helper. */}}
{{- if and (not (isset .Params "slot")) (ne .Params.slot "") -}}
{{- if and (not (isset .Params "slot")) (ne .Params.slot "") (ne .Params.hide true) -}}
{{/* Cleanup .Name to be more useful within fragments */}}
{{- $page_scratch.Set "tmp_name" (cond (eq $page .) .File.BaseFileName (strings.TrimSuffix ".md" (replace .Name "/index.md" ""))) -}}
{{- if ne $page.Language nil -}}
Expand Down
2 changes: 1 addition & 1 deletion layouts/partials/helpers/fragments.html
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
{{- $directory_same_name := in ($page_scratch.Get "fragments_directory_name") (printf "%s%s/" $root.File.Dir (replace $name ".md" "")) -}}
{{- if and (not .Params.disabled) (isset .Params "fragment") (not $directory_same_name) -}}
{{- if or $is_404 (ne .Params.fragment "404") -}}
{{- if and (eq .Params.fragment "config") (not (where ($page_scratch.Get "page_config") ".Name" $name)) -}}
{{- if and (eq .Params.fragment "config") (not (where ($page_scratch.Get "page_config") ".Name" $name)) (ne .Params.hide) -}}
{{- $page_scratch.Add "page_config" . -}}
{{- else if not (where ($page_scratch.Get "page_fragments") ".Name" $name) -}}
{{- $page_scratch.Add "page_fragments" . -}}
Expand Down