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, Runway

Runway: Set default route for all pages

I'm building a multi-lingual Runway site. The language is set like this:

<?php

$validLangs = array('en','zh','fr','es','pt');
$currentURI = explode('/', $_SERVER['REQUEST_URI']);
$lang = $currentURI[1];

// redirect to correct language if necessary
if (!in_array($lang, $validLangs)) {
  $browserLangs = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
  foreach ($browserLangs as $thisLang) {
    $thisLangPrefix = substr($thisLang,0,2);
    if (in_array($thisLangPrefix, $validLangs)) {
      $currentURI[1] = $thisLangPrefix.'/'.$currentURI[1];
      break;
    }
    $currentURI[1] = 'en/'.$currentURI[1];
  }
  $currentURI = join('/', $currentURI);
  header('Location: http://'.$_SERVER['SERVER_NAME'].$currentURI);
}

// replace Perch title with current language title if it exists
if (!empty(perch_page_attribute($lang.'_page_title',['template'=>'title-nav-text.html'],true))) {
  perch_page_attributes_extend(array(
    'pageTitle' => perch_page_attribute($lang.'_page_title',['template'=>'title-nav-text.html'],true)
  ));
}

// set Perch lang variable
PerchSystem::set_var('lang', $lang);

I'm also giving editors the ability to create their own pages using a master template which looks like:

<?php
include($_SERVER['DOCUMENT_ROOT'].'/incl/set_lang.php');
perch_layout('global/header');
?>

        <div class="section">
        <?php
            perch_content_create('Content', array(
              'template' => 'shared/text_block.html',
              'multiple' => false,
              'edit-mode' => 'singlepage',
            )); 
            perch_content_custom('Content'); 
        ?>
        </div>

<?php
perch_layout('global/footer');

For this to work, every page needs a route that looks like [lang]/page-path. It would be great if I could somehow set this default route for all pages so that the editor doesn't need to create this route every time they create a new page. Can this be accomplished through .htaccess or some Runway setting somehow?

Shane Lenzen

Shane Lenzen 18 points

  • 3 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

This isn't something we have plumbing in place for currently, but it is something we've been thinking about adding.

Got it. Thanks for the quick reply, Drew.