template building

Template Building never was easyer than with json cms.
There are 4 Files in Template directory

if you start to build your own template, you will need three functions:

<!-- gives you the page title -->
<?php echo getTitle() ?>

<!-- as example -->
<h1><?php echo getTitle() ?></h1>
<!-- This is the function to output Menu -->
<?php echo getMenu("YOUR MENU NAME","HANDLE FUNCTION") ?>

<!-- Write the navigation "MAIN_MENU" -->
<nav><?php echo getMenu("MAIN_MENU","mainMenuHandle") ?></nav>

<!-- detailed infos to mainMenuhandle in menu.php in base template -->
<!-- gives you all the page contents -->
<?php echo getContents() ?>

<!-- for example the output of the whole site -->
<main>
      <!-- output the tilte as h1 -->
      <h1><?php echo getTitle() ?></h1>
      <!-- output the contents of the site -->
      <?php echo getContents() ?>
</main>

To start at zero, you could use a code like this:

index.php

<?php
  include "getData.php";
  include "menu.php";
  include "site.php";
?>

<!DOCTYPE html>
<html>
  <head>
    <title><?php echo getTitle() ?></title>
  </head>

  <body>
    <nav><?php echo getMenu("MAIN_MENU","mainMenuHandle") ?></nav>
    <main>
      <h1><?php echo getTitle() ?></h1>
      <?php echo getContents() ?>
    </main>
    <footer><nav><?php echo getMenu("META_MENU","mainMenuHandle") ?></nav></footer>
  </body>

</html>

getData.php

<?php

// Handle sitelist for menĂ¼ and site
$filename="admin/data/__sitelist.json";
$fo = fopen($filename,"r");
$__sitelist = json_decode(fread($fo, filesize($filename)));

// Handle the site data
$title=$__sitelist->sites[0]->title;
$file=$__sitelist->sites[0]->file;
$get_file=isset($_GET['title']) ? $_GET['title'] : '';

//if sitename given via get
if($get_file!=""){
  $file=$get_file.".json";
}
//Add the path to file
$file="admin/data/".$file;
$fo_content = fopen($file,"r");
$__contents = json_decode(fread($fo_content, filesize($file)));

?>

menu.php

<?php

  //Search Menu group (first childNodes of __sitelist.menu)
  function getMenu($name,$handle){
    for($i=0; $i<count($GLOBALS["__sitelist"]->menu); $i++){
      if($GLOBALS["__sitelist"]->menu[$i]->title == $name){
        $code=$handle($GLOBALS["__sitelist"]->menu[$i]->sub);
        return $code;
        break;
      };
    }
  }
  //Handlefunction - that calls itself recursivly till all menus got
  function mainMenuHandle($m){
    $code="";
    foreach ($m as $menupoint){
      $link=getLink($menupoint->id);
      $target="_top";
      if($menupoint->action!="")$link=$menupoint->action;
      if($menupoint->target!="")$target=$menupoint->target;
      $code.="<li><a href='".$link."' target='".$target."'>".$menupoint->title."</a>";
      if(count($menupoint->sub)>0){
        $code.=mainMenuHandle($menupoint->sub);
      }
      $code.="</li>";

    }
    return "<ul>".$code."</ul>";
  }

  //Helper function to search link from __sitelist.sites
  function getLink($menuid){
    global $baseurl;
    $link="#";
    foreach($GLOBALS["__sitelist"]->sites as $site){
      if($site->menuid==$menuid){
        $link=$baseurl."/".preg_replace('/\\.[^.\\s]{3,4}$/', '', $site->file)."/";
        break;
      }
    }
    return $link;
  }

?>

site.php

<?php

  //Gives Page Title
  function getTitle(){
    return $GLOBALS["__contents"]->title;
  }

  //Gives the contents
  function getContents(){
    global $baseurl;
    $code="";

    foreach ($GLOBALS["__contents"]->content as $element){

      switch ($element->type) {
          case "text":
              $code.="<div class='item text'>".$element->content."</div>";
              break;
          case "headline":
              $code.="<h".$element->content->type." class='item text'>".$element->content->content."</h".$element->content->type.">";
              break;
          case "code":
              $search=array("<",">");
              $replace=array("<",">");
              $code.="<pre class='item code'><code class='language-php'>".str_replace($search,$replace,$element->content)."</code></pre>";
              break;
          case "image":
              $code.="<figure class='item image'><img src='$baseurl/admin/".$element->content->image."' alt='".$element->content->description."'><figcaption>".$element->content->description."</figcaption></figure>";
              break;
          case "text_image":
              $img="/admin/".$element->content->image;
              $code.="<div class='item text_image ".$element->content->align."'><div>".$element->content->text."</div><a href='".$baseurl.$img."'><img src='".$baseurl.$img."'></a></div>";
              break;
          case "gallery":
              $code.="<div class='item gallery'>";
              foreach ($element->content as $img) {
                $url="/admin/".$img->src;
                $link="/admin/".$img->srcbig;
                $code.="<a href='".$baseurl.$link."'><img src='".$baseurl.$url."'><span>".$img->description."</span></a>";
              }
              $code.="</div>";
              break;
          case "downloads":
              $code.="<div class='item downloads'>";
              foreach ($element->content as $download) {
                $url="/admin/".$download->filename;
                $code.="<a href='".$url."'>".$download->name."</a>";
              }
              $code.="</div>";
              break;
          case "video":
              $code.="<div class='item video'><div class='youtube'><iframe src='https://www.youtube.com/embed/".$element->content->id."' frameborder='0' allowfullscreen></iframe></div></div>";
              break;
          case "html":
              $code.="<div class='item html'>".$element->content."</div>";
              break;

      }

    }

    return $code;

  }

?>