We are transitioning over to a new forum platform. Please post new issues there. Existing threads will be dealt with here unless you choose to move them over. Visit the new forum

Forum

Thread tagged as: Question, Blog

Language conditional inside blog's post template

Hi, I am running a multilingual blog and I would like to avoid making separated posts for each lang. I'd rather prefer to have one post template and have those options together and then make some kind of conditional to filter using $lang variable. Any idea? — Thanks!

<h2><perch:blog id="postTitle-es" type="text" label="Title (spanish)" required="true" /></h2>
<h2><perch:blog id="postTitle-en" type="text" label="Title (english)" required="true" /></h2>
<h2><perch:blog id="postTitle-fr" type="text" label="Title (french)" required="true" /></h2>
Raul Serrano

Raul Serrano 0 points

  • 3 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, that should work fine. What problem are you hitting?

I don't know how to show only current $lang content Drew. Thanks for fast reply

Drew McLellan

Drew McLellan 2638 points
Perch Support

<h2>
<perch:if id="lang" value="es"><perch:blog id="postTitle-es" type="text" label="Title (spanish)" required="true" /></perch:if>
<perch:if id="lang" value="en"><perch:blog id="postTitle-en" type="text" label="Title (english)" required="true" /></perch:if>
<perch:if id="lang" value="fr"><perch:blog id="postTitle-fr" type="text" label="Title (french)" required="true" /></perch:if>
</h2>

It appears empty after saving blog post...

"




"
Drew McLellan

Drew McLellan 2638 points
Perch Support

Are you passing lang into the template?

I put this on post.php

<?php
    session_start();
    if (isset($_GET['lang']) && $_GET['lang']!='') {
      $lang = $_GET['lang'];
      $_SESSION['lang'] = $lang;
    }elseif (isset($_SESSION['lang'])){
      $lang = $_SESSION['lang'];
    }else{
      // default language
      $lang = 'es';
    }
?>

Should I add something like this?

<?php
    PerchSystem::set_var('lang', $lang);
    perch_blog_custom('My region', array(
        'template'=>'post.html'
    ));
?>
Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, looks just right. What's happening?

Yes it works, should I take out 'My region'?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, that part isn't correct.

<?php PerchSystem::set_var('lang', $lang);
perch_blog_custom(array(
'template'=>'post.html'
)); ?>

Thats better?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes - is something not working?

It works, thanks Drew!