# "Current" variable for fields in both Pages and Sections

**URL:** <https://zola.discourse.group/t/current-variable-for-fields-in-both-pages-and-sections/935>\
**Category:** Feature requests\
**Created:** [June 5, 2021, 7:33am UTC](https://zola.discourse.group/t/current-variable-for-fields-in-both-pages-and-sections/935 "2021-06-05T07:33:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![thumbs](https://avatars.discourse-cdn.com/v4/letter/t/e0b2c6/32.png) [@thumbs](https://zola.discourse.group/u/thumbs)\
**Post date:** [June 5, 2021, 7:33am UTC](https://zola.discourse.group/t/current-variable-for-fields-in-both-pages-and-sections/935/1 "2021-06-05T07:33:17Z")

</div>

I’m not sure if this exists already, but I wasn’t able to find it in the docs. Would it be possible to have a common variable `current` that checks whether it’s a page or a section? This would be similar to `current_path` and `current_url`, but covering more variables and fields.

A number of [shared terms](https://zola.discourse.group/t/section-vs-page/522/3) exist in both sections and pages, and this could simplify writing templates.

As an example, in the `<head>` of my `base.html`, I have this block:

```auto
<title>{% block head_title %}{% endblock head_title %}</title>

```

In my templates for _pages_, I define this:

```auto
{% block head_title %}{{ page.title | safe }} | {{ config.title | safe }} | {{ page.description | safe }}{% endblock head_title %}

```

For _sections_, this block would be:

```auto
{% block head_title %}{{ section.title | safe }} | {{ config.title | safe }} {{ section.description | safe }}{% endblock head_title %}

```

Both of these could be replaced by a single line in `base.html`

```auto
<title>{{ current.title | safe }} | {{ config.title | safe }} | {{ current.description | safe }}</title>

```

---

<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:** [June 5, 2021, 7:51am UTC](https://zola.discourse.group/t/current-variable-for-fields-in-both-pages-and-sections/935/2 "2021-06-05T07:51:18Z")

</div>

Related issue: [Templates need a variable that could be “section” or “page” · Issue #687 · getzola/zola · GitHub](https://github.com/getzola/zola/issues/687)

---

<div class="post-metadata">

**Author:** ![thumbs](https://avatars.discourse-cdn.com/v4/letter/t/e0b2c6/32.png) [@thumbs](https://zola.discourse.group/u/thumbs)\
**Post date:** [June 5, 2021, 8:12am UTC](https://zola.discourse.group/t/current-variable-for-fields-in-both-pages-and-sections/935/3 "2021-06-05T08:12:33Z")

</div>

I knew I hadn’t searched hard enough 🙂

Thanks! This works exactly as expected.

```auto
{%- if page %}
	{%- set resource = page %}
{%- elif section %}
	{%- set resource = section %}
{%- endif %}

```
