{{- /* cta-button.html — the ONLY place an affiliate link is constructed. Link = brand.affiliateBaseUrl ? brand.affiliateSubIdParam = . Never hardcode a raw affiliate URL anywhere else. Call with a dict: {{ partial "cta-button.html" (dict "page" . "text" "Play Now") }} Optional keys: subid, style ("primary"|"secondary"), size ("lg"), class, block(bool). Sub-id resolution (robust when .File is nil for generated pages): explicit subid -> .File.ContentBaseName -> .Type -> "home" ContentBaseName equals the classic BaseFileName for standard pages and, unlike BaseFileName, yields the real slug for page bundles (e.g. games). */ -}} {{- $page := .page -}} {{- $brand := $page.Site.Data.brand -}} {{- $text := .text | default "Visit Casino" -}} {{- $style := .style | default "primary" -}} {{- $size := .size | default "" -}} {{- $affiliateURL := $brand.affiliateBaseUrl | default "" -}} {{- $siteURL := strings.TrimSuffix "/" $page.Site.BaseURL -}} {{- $targetURL := strings.TrimSuffix "/" $affiliateURL -}} {{- if and $affiliateURL (ne $targetURL $siteURL) -}} {{- $subid := .subid | default "" -}} {{- if not $subid -}} {{- if $page.IsHome -}} {{- $subid = "home" -}} {{- else -}} {{- with $page.File -}}{{- $subid = .ContentBaseName -}}{{- end -}} {{- end -}} {{- end -}} {{- if not $subid -}}{{- $subid = $page.Type -}}{{- end -}} {{- if or (eq $subid "_index") (eq $subid "") -}}{{- $subid = "home" -}}{{- end -}} {{- $href := printf "%s?%s=%s" $affiliateURL $brand.affiliateSubIdParam $subid -}} {{- $classes := "btn-primary" -}} {{- if eq $style "secondary" -}}{{- $classes = "btn-secondary" -}}{{- end -}} {{- if eq $style "ghost" -}}{{- $classes = "btn-ghost" -}}{{- end -}} {{- if $size -}}{{- $classes = printf "%s btn-%s" $classes $size -}}{{- end -}} {{- if .block -}}{{- $classes = printf "%s w-full" $classes -}}{{- end -}} {{- with .class -}}{{- $classes = printf "%s %s" $classes . -}}{{- end -}} {{ $text }} {{- end -}}