Forum

Thread tagged as: Question, Problem

Perch conditional not working on content template

Hi, I'm using

<perch:if id="lang" value="es">xyz</perch:if>

to filter content by language on my content templates, but they do not work (on blog templates they do). Anyone knows why?

I use php code to set variable:

include('perch/runtime.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';
    }

 PerchSystem::set_var('lang', $lang);

Diagnostic report

Perch: 3.0.4, PHP: 5.4.4, MySQL: 5.5.25, with PDO
Server OS: Darwin, apache2handler
Installed apps: content (3.0.4), assets (3.0.4), categories (3.0.4), perch_blog (5.5.1)
App runtimes: <?php $apps_list = [ perch_blog, ];
PERCH_LOGINPATH: /perch
PERCH_PATH: /Applications/MAMP/htdocs/optaarquitectos.com/perch
PERCH_CORE: /Applications/MAMP/htdocs/optaarquitectos.com/perch/core
PERCH_RESFILEPATH: /Applications/MAMP/htdocs/optaarquitectos.com/perch/resources
Image manipulation: GD
PHP limits: Max upload 32M, Max POST 32M, Memory: 64M, Total max file upload: 32M
F1: 0c66c2e1f82f9e0b7617b2cb8270f2c7
Resource folder writeable: Yes
HTTP_HOST: opta2:8888
DOCUMENT_ROOT: /Applications/MAMP/htdocs/optaarquitectos.com
REQUEST_URI: /perch/core/settings/diagnostics/
SCRIPT_NAME: /perch/core/settings/diagnostics/index.php
Raul Serrano

Raul Serrano 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

How are you displaying your region? I can't see that in the code you've shown.

<?php perch_content('Home'); ?>
Drew McLellan

Drew McLellan 2638 points
Perch Support

The perch_content() function uses the cached HTML that is generated when your region is edited. Therefore it doesn't know anything about any variables that you set at runtime. Instead, you can do this:

perch_content_custom('Home');