Default function and partial

How would I combine default function and partial function?

{{ index .Params "actions" | default .Site.Data.global.actions  }}

Thought something like this, but syntax is off.

{{ partial "actions" .Params.actions | default .Site.Data.global.actions }} 

Or is’t better to use a simple if/else block?

  {{if .Params.actions}}
    {{ partial "actions" .Params.actions }} 
  {{ else }}
    {{ partial "actions" .Site.Data.global.actions }} 
  {{ end }}

Hi @frankspin89,

what kind of error do you get?

Without test it I would say it looks fine. If I had to guess I would say that the template engine complains that you try to pass to many arguments.

Give this a try:

{{ partial "actions" (.Params.actions | default .Site.Data.global.actions) }}

@digitalcraftsman thanks that is working great.

Is there a option to set the default value conditional? Looking for something like this

{{ partial "actions" (.Params.actions | default if .Params.defaults.actions( .Site.Data.defaults.actions))  }} 

So I only want to set the default value if .Params.defaults.actions is true.

I guess you can get rid of the if and wrap the statement behind it in parentheses. .Params.defaults.actions( .Site.Data.defaults.actions) does either return nil or a value.

Read it as: if there is no value return nil, otherwise the value.