Forum

Thread tagged as: Question, Problem

[Multi-lingual site] perch_content() with if statements

Hi there,

For a multi-lingual site, I use perch_content('My region - '.$lang); to localise a given region. It works but this solution isn't ideal when there's a lot of perch_content() for a particular page; it makes the interface tedious to read and maintain. To simplify that, my idea was to bring the logic of which language to show in the template rather than the page.

<perch:if id="current_language" match="eq" value="fr">
    <perch:content id="text_fr" type="text" label="Text FR" required="true" title="true" />
<perch:else />
    <perch:content id="text_en" type="text" label="Text EN" required="true" title="true" />
</perch:if>

This isn't working – but does work when used with perch_collection() or perch_content_custom(). Regardless of the language, it seems to ignore the first statement and to go straight to the last. In my example, it's simply showing the english value. I guess the variable can't be passed to the template with perch_content()?

Am I missing something? Is there any alternative while still using perch_content()?

**

I am planning to use perch for a bigger project in the future in 4 languages, I'm trying to figure out the best possible way to prevent the interface to be un-readable – knowing that I do want to maintain only one site.

Thanks. Cheers!

Robin Pick

Robin Pick 5 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

The HTML output of perch_content() is generated and cached at edit time. At that point the language option isn't available.

Anything that uses environment information like this needs to be processed as the page loads - which is why you need to use perch_content_custom() in its place.

Thanks for the explanation!