Re: 'Forms' app liquid tag (using form ID)

How can I use a Forms app liquid tag for different languages?

n0glitch
Shopify Partner
2 0 1

Hi!


I want to insert an inline form on my blog with the 'Forms' app, but I have different languages, using the 'Markets' feature and the 'Translate and Adapt' app.

I have created 5 different forms for 5 languages (EN, DE, FR, IT, ES), each with their own ID.


Is there a liquid tag for Forms, per ID, that I could easily insert in my article template code? This is what it looks like now:

 {% assign locale = request.locale %}
  {% if locale == 'en' %}
    {% render 'form-EN' %}
  {% elsif locale == 'de' %}
    {% render 'form-DE' %}
  {% elsif locale == 'fr' -%}
    {% render 'form-FR' %}
  {% elsif locale == 'it' -%}
    {% render 'form-IT' %}
  {% elsif locale == 'es' %}
    {% render 'form-ES' %}
  {% else %}
    {% render 'form-EN' %}
  {% endif %}

I would like to use a Forms liquid tag that I can write in my different 'form-language' snippets, but I can't find a solution.

 

Thanks in advance!

 

P.S.: I know I could install other translation or forms apps, but that would add some complexity and costs so it's not ideal.

n0glitch.com - cognitive and physical optimisation
Replies 2 (2)

Samia_Akram22
Shopify Partner
60 10 16

@n0glitch 

Certainly! To achieve this, you can use the `{% form 'form-ID' %}` liquid tag in your code. Here's how you can modify your template:

```liquid
{% assign locale = request.locale %}

{% form 'form-' | append: locale %}
```

This assumes that your form IDs are constructed as 'form-EN', 'form-DE', etc. The `append` filter will concatenate 'form-' with the current locale, giving you the correct form ID dynamically.

This simplifies your code and makes it more scalable, especially when adding more languages in the future.

Problem Solved? ✔Accept and Like solutions to help future merchants.
n0glitch
Shopify Partner
2 0 1

This is not working, and also the form ID is assigned automatically there's no way to edit it.

n0glitch.com - cognitive and physical optimisation