Skip to content

Default Values

Q edited this page Aug 17, 2020 · 6 revisions

By default, if the data returned to a willow is not in a format that can be rendered, either an array of strings, integers or booleans or an array of strings, integers or booleans and indexed arrays of strings, integers or booleans, the willow is not rendered.

However, it is possible to stipulate default data to render, either globally, or on a per-field basis, by passing the default value in template configuration, here is an example:

{~ user~member_connections {+ [a] config->default = all: "<p class='ml-3'>No members here, yet...</p>" +} ~}

Willow will try to locate and return data from the user::member_connections class method, if the data returns correctly formatted, the default value is ignored. However, if the data is empty of mal-formed, the default value is used to replace single or all fields - which is determined by the values passed in the configuration array.

Here are 3 possible variants of the passed configuration:

  • config->default = one: "<p class='ml-3'>No members here, yet...</p>"
  • config->default = one: "<p class='ml-3'>No members here, yet...</p>" & two: "<p class='ml-3'>Oops, sorry</p>"
  • config->default = all: "<p class='ml-3'>No members here, yet...</p>"

The first example above replaces the key "one" in the returned data array - if it exists and is empty - with the default value.

The second example above replaces the keys "one" and "two" in the returned data array - if they exists and are empty - with the default value.

The final example above replaces all keys in the returned data array - if they exists and is empty - with the default value, this is most useful for loops which return empty data arrays.

Clone this wiki locally