سؤال

أقوم بتشغيل MAMP كخادم محلي. لقد قمت بتثبيت غصين في /Applications/MAMP/svn/twig/twig/lib. لقد قمت بتضمين هذا المسار في ملف php.ini الخاص بي:

include_path = ".:/Applications/MAMP/bin/php5.3/lib/php:/Applications/MAMP/svn/zendframework/trunk/library:/Applications/MAMP/svn/twig/twig/lib";

ما الذي يحتاج إلى الذهاب إلى مجلد HTDOCS الخاص بي من أجل أن يكمل التثبيت والوصول إلى غصين؟

هل كانت مفيدة؟

المحلول

لا تحتاج إلى تثبيت أي شيء ، يمكنك فقط استخدامه في PHP. إليك نصًا بسيطًا لتحميله وتقديم قالب:

require_once( "Twig/Autoloader.php" );

Twig_Autoloader::register();
// Load template files from the ./tpl/ folder and use ./tpl/cache/ for caching
$twig = new Twig_Environment( new Twig_Loader_Filesystem("./tpl"),
    array( "cache" => "./tpl/cache" ) );

// Load and render 'template.tpl'
$tpl = $twig->loadTemplate( "template.tpl" );
echo $tpl->render( array("msg"=>"Hello, World!") );

يمكن أن يبدو القالب الخاص بك مثل هذا:

<html>
    <!-- ... -->
    <body>
        <h1>{{ msg|e }}</h1>
    </body>
</html>

هذا المثال سوف يهرب ويتردد "مرحبًا ، العالم".

لمزيد من المعلومات ، فقط اقرأ الوثائق لـ (PHP) التطوير و مصممي القالب.

نصائح أخرى

include __DIR__ . "/vendor/twig/twig/lib/Twig/Autoloader.php";  

//register autoloader  

Twig_Autoloader::register();  

//loader for template files  

$loader = new Twig_Loader_Filesystem('templates');  

//twig instance  

$twig = new Twig_Environment($loader, array('cache' => 'cache'));  

//load template file  

$template = $twig->loadTemplate('index.html');  

//render a template  

echo $template->render(array('title' => 'Welcome to Twig template'));  

ابحث عن مزيد من المعلومات حول هذا الدورة التعليمية

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top