conditional-text.html 1.7 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <!-- Get the current buildcondition from the config and lowercase it -->
  2. {{- $condition := lower $.Site.Params.buildCondition -}}
  3. {{- if ne $condition "" -}}
  4. <!-- Get the parameters from the shortcode invocation and lowercase them.
  5. TODO: to enable multiple conditions, we could accept comma-separated lists and split them -->
  6. {{- $include_if := lower (.Get "include-if") -}}
  7. {{- $exclude_if := lower (.Get "exclude-if") -}}
  8. {{- if and (in $include_if $condition) (in $exclude_if $condition) -}}
  9. <!-- condition appears in both parameters -->
  10. {{- errorf "Build condition %q appears in both include-if and exclude-if parameters of conditional-txt shortcode on page %s" $condition .Position -}}
  11. {{- end -}}
  12. {{- if isset $.Params "include-if" -}}
  13. <!-- WARNING substring matches are matches as well! That means, if include-if="foobar", and buildcondition is "foo", you have a match!-->
  14. {{- if in $include_if $condition -}}
  15. <!-- Do not indent the next Inner line, because the inner becomes a blockquote if the conditional-text is nested in another shortcode -->
  16. {{- .Inner -}}
  17. {{- else -}}
  18. {{- end -}}
  19. {{- else -}}
  20. {{- if isset $.Params "exclude-if" -}}
  21. <!-- WARNING substring matches are matches as well! That means, if exclude-if="foobar", and buildcondition is "foo", you have a match!-->
  22. {{- if in $exclude_if $condition -}}
  23. {{- else -}}
  24. <!-- Do not indent the next Inner line, because the inner becomes a blockquote if the conditional-text is nested in another shortcode -->
  25. {{- .Inner -}}
  26. {{- end -}}
  27. {{- end -}}
  28. {{- end -}}
  29. {{- end -}}