language_variants – Variable issue Draft Status?

I’m building a custom language switcher using the language_variants(‘localized’) function, but I’ve run into a limitation. It seems like there’s no documented way to check whether a localized page is a draft or published.

Issue

  1. HubSpot has great documentation, but for deep-level coding scenarios like this, there is no reference to isDraft or any similar property for language variants.
  2. The language_variants() function returns localized pages, but I can’t find a way to filter out draft pages.

<div class="header_lag_switcher">{% set languages = language_variants('localized') %}<div class="lag_switcher {{ "no-lang" if languages|length == 0 }}">{% set activeLanguage = languages|selectattr('isActive', true)|first %}<ul class="hs-language-switcher" role="menu">{% for language in languages %}<li class="{{ "lag__actvie" if language.languageCode|escape_attr == html_lang }}"><alang="{{ language.languageCode|escape_attr }}"hreflang="{{ language.languageCode|escape_attr }}"href="{{ language.localizedUrl|escape_url }}"data-value="{{ language.languageDisplayName|escape_attr }}">{{ language.languageCode|escape_attr }}</a></li>{% endfor %}</ul></div></div>

What I Need Help With

  1. Does HubSpot expose a way to check if a localized page is a draft?
  2. Is there any undocumented property like isDraft or another method to filter drafts from language_variants()?
  3. If not, what’s the best workaround to ensure that draft pages don’t appear in the language switcher?

Any insights would be greatly appreciated! If someone from HubSpot can confirm whether this is possible (or missing from documentation), that would be great. :rocket:

Thanks in advance! :blush:

Hi, @2CUBE-Studio :waving_hand: Thanks for posting. It’s a great question. I’d like to invite some of our community members to the conversation — hey @Anton @pm8rsh88 @BarryGrennan have you tackled anything similar?

Thank you very much for taking a look! — Jaycee

Hi @2CUBE-Studio ,
{{ content.state }} will show you on the individual page whether the page is “DRAFT” or “PUBLISHED_OR_SCHEDULED”.
Incidentally you can dig into a lot of page info that wouldn’t necessarily be in the documentation by using the Developer Info on the cog menu on each page.


Barry Grennan

Freelance HubSpot CMS Developer

Website | Contact | LinkedIn