Kontakt aufnehmen

Menü Templates Teil 2 (CMS)

Weiter geht’s mit einer Erweiterung der Templates. Ab jetzt kann man mit {IF:Name} eine If-Abfrage einbauen. Mit der Funktion show_if kann man diese dann zuweisen. Dafür gibt es in der /system/classes/template.php die Eigenschaft ifs und die Methode removeHiddenIfBlocks:

<?php
  class Template{
    private $template = "";
    private $loop_templates = array();
    private $template_path = "";
    private $loops = array();
    private $ifs = array();
  
   ...    
    private function removeHiddenIfBlocks($template){
      preg_match_all("/{IF:([w]+)[^}]*}((s*?.*?)*){/IF:\1}/", $template, $matches, PREG_SET_ORDER);
      foreach ($matches as $match){
        if(!array_key_exists(strtoupper($match[1]), $this->ifs)){
          $template = str_ireplace($match[0], "", $template);
        }
        elseif(!$this->ifs[strtoupper($match[1])]){
          $template = str_ireplace($match[0], "", $template);
        }
        else{
          $template = str_ireplace($match[0], $match[2], $template);
        }
      }
      return $template;
    }
    
    public function getCode(){
      $this->template = $this->removeHiddenIfBlocks($this->template);
      foreach($this->loops as $key => $array){
        $loop_template = implode("n",$array);
        $this->template = str_ireplace('<!--LOOP('.strtoupper($key).')-->', $loop_template, $this->template);
      }
      $this->replaceLanguageTokens();
      $this->replaceIcons();
      return $this->template;
    }
  
    public function output(){
      echo $this->getCode();
    }
  }
?>

Du arbeitest in einer Agentur oder als Freelancer?
Dann wirf doch mal einen Blick auf unsere Software FeatValue.

Über uns

Stefan Wienströer

Wir entwickeln Webanwendungen mit viel Leidenschaft. Unser Wissen geben wir dabei gerne weiter. Mehr über a coding project

Cookie-Einstellungen

Helfen Sie dabei, uns noch besser zu machen. Wir nutzen Cookies und ähnliche Technologien, um die Website auf Ihre Bedürfnisse anzupassen. Zur Datenschutzerklärung

Auswahl speichern