kirby/branches/multilang/page.php
/**
   * Returns the content object for this page
   *
   * @param string $lang optional language code
   * @return Content
   */
Returns the content object for this page
@param string $lang optional language code
@return Content
Returns the content object for this page @param string $lang optional language code @return Content
public function content($lang = null) {
    if(is_null($lang)) {
      if(isset($this->cache['content'])) return $this->cache['content'];
      $content = $this->_content($this->site->language->code);
      if($this->site->language->code != $this->site->defaultLanguage->code) {
        $defaultContent = $this->_content($this->site->defaultLanguage->code);
        foreach($defaultContent->data as $key => $field) {
          if(!isset($content->data[$key]) || $content->data[$key]->value == '') {
            $content->data[$key] = $field;
          }
        }
      }
      return $this->cache['content'] = $content;
    } else {
      return $this->_content($lang);
    }
  }
public function content ( $ lang = null ) { if ( is_null ( $ lang ) ) { if ( isset ( $ this -> cache [ 'content' ] ) ) return $ this -> cache [ 'content' ] ; $ content = $ this -> _content ( $ this -> site -> language -> code ) ; if ( $ this -> site -> language -> code != $ this -> site -> defaultLanguage -> code ) { $ defaultContent = $ this -> _content ( $ this -> site -> defaultLanguage -> code ) ; foreach ( $ defaultContent -> data as $ key => $ field ) { if ( ! isset ( $ content -> data [ $ key ] ) || $ content -> data [ $ key ] -> value == '' ) { $ content -> data [ $ key ] = $ field ; } } } return $ this -> cache [ 'content' ] = $ content ; } else { return $ this -> _content ( $ lang ) ; } }
Returns the content object for this page
 @param string $lang optional language code
 @return Content
Returns the content object for this page @param string $lang optional language code @return Content
// get the content for the current language // the current language's content can be cached // get the current content // get the fallback content // fetch the default language content // replace all missing fields with values from the default content // find and cache the content for this language // get the content for another language