Welcome to mirror list, hosted at ThFree Co, Russian Federation.

conditional-text.html « shortcodes « layouts - github.com/google/docsy.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ee7b2308e8be197fb862a7f0195aa2d4aa5d4e59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<!-- Get the current buildcondition from the config and lowercase it -->
{{- $condition := lower $.Site.Params.buildCondition -}}

{{- if ne $condition "" -}}
    
    <!-- Get the parameters from the shortcode invocation and lowercase them.
    TODO: to enable multiple conditions, we could accept comma-separated lists and split them -->
    {{- $include_if := lower (.Get "include-if") -}}
    {{- $exclude_if := lower (.Get "exclude-if") -}}

    {{- if and (in $include_if $condition) (in $exclude_if $condition) -}}
        <!-- condition appears in both parameters -->
        {{- errorf "Build condition %q appears in both include-if and exclude-if parameters of conditional-txt shortcode on page %s" $condition .Position -}}
    {{- end -}}

    {{- if isset $.Params "include-if" -}}
        <!-- WARNING substring matches are matches as well! That means, if include-if="foobar", and buildcondition is "foo", you have a match!-->
        {{- if in $include_if $condition -}}
<!-- Do not indent the next Inner line, because the inner becomes a blockquote if the conditional-text is nested in another shortcode  -->
{{- .Inner -}}
        {{- else -}}
        {{- end -}}
    {{- else -}}

        {{- if isset $.Params "exclude-if" -}}
            <!-- WARNING substring matches are matches as well! That means, if exclude-if="foobar", and buildcondition is "foo", you have a match!-->
            {{- if in $exclude_if $condition -}}
            {{- else -}}
<!-- Do not indent the next Inner line, because the inner becomes a blockquote if the conditional-text is nested in another shortcode  -->
{{- .Inner -}}
            {{- end -}}
        {{- end -}}

    {{- end -}}

{{- end -}}