# Ternary conditional for tera set or macro

**URL:** <https://zola.discourse.group/t/ternary-conditional-for-tera-set-or-macro/2041>\
**Category:** Support\
**Created:** [February 3, 2024, 1:51am UTC](https://zola.discourse.group/t/ternary-conditional-for-tera-set-or-macro/2041 "2024-02-03T01:51:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![adrianboston](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/adrianboston/32/907_2.png) [@adrianboston](https://zola.discourse.group/u/adrianboston)\
**Post date:** [February 3, 2024, 1:51am UTC](https://zola.discourse.group/t/ternary-conditional-for-tera-set-or-macro/2041/1 "2024-02-03T01:51:54Z")

</div>

Is there a ternary conditional that might be used to set a value  
ie.

`{% set mylength = config.extra.content_length is defined ? config.extra.content_length : 200;`

opposed to the if else double set

```auto
{% if config.extra.content_length is defined %}
{% set mylength = config.extra.content_length
{% else %}
{% set mylength = 200
{%end%}

```

alternatively, theres the following in the [tera assignment](https://keats.github.io/tera/docs/#assignments) suggesting some ability to set from a macro.

`{% set my_var = macros::some_macro() %}`

how would that function ?

```auto
{% macro set_ternary(condition, value_true, value_false) %}
    {% if condition %}
        value_true
    {% else %}
        value_false
    {% endif %}
{% endmacro set_ternary %}

```

---

<div class="post-metadata">

**Author:** ![keats](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@keats](https://zola.discourse.group/u/keats)\
**Post date:** [February 3, 2024, 8:40pm UTC](https://zola.discourse.group/t/ternary-conditional-for-tera-set-or-macro/2041/2 "2024-02-03T20:40:00Z")

</div>

Not currently but I’ve added them to Tera v2 last week: [Ternary (#31) · Keats/tera2@e8577ab · GitHub](https://github.com/Keats/tera2/commit/e8577abe07485af6fdd39d2dc77b8df25185eb98)
