ücretsiz hafif şablon sistemi

6 Cevap

PHP ile saf yapılan herhangi bir ücretsiz, hafif, non-MVC şablon sistemleri var mı? Ben Smarty ilgilenmiyorum.

6 Cevap

Sure:

<?php require("Header.php"); ?>

  <h1>Hello World</h1>
  <p>I build sites without "smarty crap"!</p>

<?php require("Footer.php"); ?>

Ben bulabildiğim en hafif biriydi.

include("header.php");

PHP Savant, temelde inline PHP kodu: http://phpsavant.com/

Eğer gerçekten {template.syntax} kullanmak istiyorsanız veya TinyButStrong bakmak olabilir: http://tinybutstrong.com/

Fabien Potencier tarafından Twig bakmak zorunda deneyin.

http://www.phpaddiction.com/tags/axial/url-routing-with-php-part-one/

Ben buldum ve uzak iyi bir öğretici. Ben OOP üzerinde benim küçük çalışma projeleri geçiş ve Usul terk bu dersi kullanılmıştır.

Eğer ciddi bir MVC gerekiyorsa, o CodeIgniter gibi test, kararlı olanlar ile gitmek her zaman iyidir - Büyük Burada ihtar ve bir şey SO anlamamı sağladı. Ben temelde (tüm çerçeve komutları relearn istemiyordu kapalı benim saf PHP asmak için MVC bir iskelet oluşturmak için bu tut kullanılır, ve ben dahil ve kullanmaya devam etmek istediğini yaptık birçok sınıfları var. )

Bu tut kilometre oldu.

İşte e-postalar için bazı hızlı çiftleşmiş yapmak ile geldi çok küçük bir sınıf bulunuyor.

/**
 * Parses a php template, does variable substitution, and evaluates php code returning the result
 * sample usage:
 *       == template : /views/email/welcome.php ==
 *            Hello {name}, Good to see you.
 *            
 *                I know you're mike
 *            
 *       == code ==
 *            require_once("path/to/Microtemplate.php") ;
 *            $data["name"] = 'Mike' ;
 *            $string = LR_Microtemplate::parse_template('email/welcome', $data) ;
 */

class Microtemplate {

/**
 * Micro-template: Replaces {variable} with $data['variable'] and evaluates any php code.
 * @param string $view name of view under views/ dir. Must end in .php
 * @param array $data array of data to use for replacement with keys mapping to template variables {}.
 * @return string
 */


public static function parse_template($view, $data) {
    $template = file_get_contents($view . ".php") ;
    // substitute {x} with actual text value from array
    $content = preg_replace("/\{([^\{]{1,100}?)\}/e", 'self::get_value("${1}", $data)' , $template);

    // evaluate php code in the template such as if statements, for loops, etc...
    ob_start() ;
    eval('?>' . "$content" . '<?php ;') ;
    $c = ob_get_contents() ;
    ob_end_clean() ;
    return $c ;
}

/**
 * Return $data[$key] if it's set. Otherwise, empty string.
 * @param string $key
 * @param array $data
 * @return string 
 */
public static function get_value($key, $data){
    if (isset($data[$key]) && $data[$key]!='~Unknown') { // filter out unknown from legacy system
        return $data[$key] ;   
    } else {
        return '' ;
    }
}

}