<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>sixhead</title>
	<atom:link href="https://sixhead.com/feed/" rel="self" type="application/rss+xml" />
	<link>https://sixhead.com</link>
	<description></description>
	<lastBuildDate>Sat, 15 Oct 2022 02:26:20 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>วิธีใช้ class Template ตอนที่ 7 tr ใน table</title>
		<link>https://sixhead.com/%e0%b8%a7%e0%b8%b4%e0%b8%98%e0%b8%b5%e0%b9%83%e0%b8%8a%e0%b9%89-class-template-%e0%b8%95%e0%b8%ad%e0%b8%99%e0%b8%97%e0%b8%b5%e0%b9%88-7-tr-%e0%b9%83%e0%b8%99-table/</link>
		
		<dc:creator><![CDATA[Chairat Sunthornwiphat]]></dc:creator>
		<pubDate>Sun, 13 Nov 2016 08:11:15 +0000</pubDate>
				<category><![CDATA[Open source]]></category>
		<category><![CDATA[template]]></category>
		<guid isPermaLink="false">http://sixhead.com/?p=240</guid>

					<description><![CDATA[ถึงจะเป็นยุคที่เราใช้ div เป็นหลักแล้วแต่ในบางเนื้อหา table ยังมีความจำเป็นอยู่ ในกรณีที่ table มีหลาย column และเราใช้ $tp->sub(); ถ้าข้อมูลไม่ครบจะไม่ถูกปิด มาดูวิธีแก้ก้น ผลการทำงาน (ปิด tag &#8220;ไม่&#8221; ถูกต้อง) ผลการทำงาน (ปิด tag ถูกต้อง) *ต้อง view source คู่กันไปด้วย สามารถทดลองเปลี่ยน item=5 เป็นจำนวนที่ต้องการได้ _tp_table.html table.php]]></description>
										<content:encoded><![CDATA[<p><span id="more-240"></span><br />
ถึงจะเป็นยุคที่เราใช้ <strong>div</strong> เป็นหลักแล้วแต่ในบางเนื้อหา <strong>table</strong> ยังมีความจำเป็นอยู่<br />
ในกรณีที่ table มีหลาย column และเราใช้ $tp->sub(); ถ้าข้อมูลไม่ครบจะไม่ถูกปิด มาดูวิธีแก้ก้น</p>
<p><strong>ผลการทำงาน (ปิด tag &#8220;ไม่&#8221; ถูกต้อง)</strong> <a href="http://sixhead.com/run/template/table.php?fix=0&#038;item=5" target="_blank" rel="noopener noreferrer"><i class="fa fa-external-link"></i></a><br />
<strong>ผลการทำงาน (ปิด tag ถูกต้อง)</strong> <a href="http://sixhead.com/run/template/table.php?fix=1&#038;item=5" target="_blank" rel="noopener noreferrer"><i class="fa fa-external-link"></i></a><br />
<strong>*ต้อง view source คู่กันไปด้วย</strong><br />
สามารถทดลองเปลี่ยน item=5 เป็นจำนวนที่ต้องการได้</p>
<p><strong>_tp_table.html</strong></p>
<pre class="brush: xml; title: ; notranslate">
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;$title&lt;/title&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;module/bootstrap/bootstrap.min.css&quot;&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;div class=&quot;container&quot;&gt;
    &lt;h3&gt;$title&lt;/h3&gt;

    &lt;table class=&quot;table table-bordered&quot;&gt;
        &lt;colgroup&gt;
            &lt;col class=&quot;col-sm-3&quot;&gt;
            &lt;col class=&quot;col-sm-3&quot;&gt;
            &lt;col class=&quot;col-sm-3&quot;&gt;
            &lt;col class=&quot;col-sm-3&quot;&gt;
        &lt;/colgroup&gt;
    &lt;!--SiXhEaD:data--&gt;
        &lt;!--sub:1--&gt;
        &lt;tr&gt;
            &lt;td&gt;$name&lt;/td&gt;&lt;!--/sub:1--&gt;
        &lt;!--sub:2--&gt;
            &lt;td&gt;$name&lt;/td&gt;&lt;!--/sub:2--&gt;
        &lt;!--sub:3--&gt;
            &lt;td&gt;$name&lt;/td&gt;&lt;!--/sub:3--&gt;
        &lt;!--sub:4--&gt;
            &lt;td&gt;$name&lt;/td&gt;
        &lt;/tr&gt;
        &lt;!--/sub:4--&gt;
    &lt;!--/SiXhEaD:data--&gt;
    &lt;/table&gt;
&lt;/div&gt;

&lt;script src=&quot;module/jquery/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;module/bootstrap/bootstrap.min.js&quot;&gt;&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p><strong>table.php</strong></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
require 'module/SiXhEaD.Template.php';

$item = (int) $_GET&#x5B;'item'];
$fix = (int) $_GET&#x5B;'fix'];
if (!$item) {
    $item = 5;
}
if ($item &gt; 100) {
    $item = 100;
}

$tp = new Template('_tp_table.html');

$title = 'วิธีการเติม table ให้เต็ม';

$tp-&gt;block('data');
$tp-&gt;sub(4);
for ($no = 1; $no &lt;= $item; $no++) {
    $name = $no;
    $tp-&gt;apply();
}

if ($fix) {
    if ($tp-&gt;getCurrentSub() != 1) {
        for ($no = $tp-&gt;getCurrentSub(); $no &lt;= 4; $no++) {
            $name = '';
            $tp-&gt;apply();
        }
    }
}

$tp-&gt;display();
exit;
</pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>วิธีใช้ class Template ตอนที่ 6 ซ้อน loop</title>
		<link>https://sixhead.com/%e0%b8%a7%e0%b8%b4%e0%b8%98%e0%b8%b5%e0%b9%83%e0%b8%8a%e0%b9%89-class-template-%e0%b8%95%e0%b8%ad%e0%b8%99%e0%b8%97%e0%b8%b5%e0%b9%88-6-%e0%b8%8b%e0%b9%89%e0%b8%ad%e0%b8%99-loop/</link>
		
		<dc:creator><![CDATA[Chairat Sunthornwiphat]]></dc:creator>
		<pubDate>Fri, 11 Nov 2016 20:07:51 +0000</pubDate>
				<category><![CDATA[Open source]]></category>
		<category><![CDATA[template]]></category>
		<guid isPermaLink="false">http://sixhead.com/?p=229</guid>

					<description><![CDATA[หมายเหตุ เป็นการนำเอา ตอนที่ 3 block (ขั้นสูง) มาแยกให้เห็นตัวอย่างเฉพาะการซ้อน loop ผลการทำงาน &#60;!DOCTYPE html&#62; &#60;html&#62; &#60;head&#62; &#60;title&#62;วิธีใช้งาน ซ้อน loop&#60;/title&#62; &#60;link rel=&#34;stylesheet&#34; href=&#34;module/bootstrap/bootstrap.min.css&#34;&#62; &#60;/head&#62; &#60;body&#62; &#60;div class=&#34;container&#34;&#62; &#60;h3&#62;วิธีใช้งาน ซ้อน loop&#60;/h3&#62; &#60;div class=&#34;alert alert-danger&#34;&#62; &#60;div class=&#34;panel panel-default&#34;&#62; &#60;div class=&#34;panel-body&#34;&#62; 1 &#60;/div&#62; &#60;/div&#62; &#60;div class=&#34;panel panel-default&#34;&#62; &#60;div class=&#34;panel-body&#34;&#62; 2 &#60;/div&#62; &#60;/div&#62; &#60;/div&#62; &#60;div class=&#34;alert alert-info&#34;&#62; &#60;div class=&#34;panel panel-default&#34;&#62; &#60;div class=&#34;panel-body&#34;&#62; 1 ... <a title="วิธีใช้ class Template ตอนที่ 6 ซ้อน loop" class="read-more" href="https://sixhead.com/%e0%b8%a7%e0%b8%b4%e0%b8%98%e0%b8%b5%e0%b9%83%e0%b8%8a%e0%b9%89-class-template-%e0%b8%95%e0%b8%ad%e0%b8%99%e0%b8%97%e0%b8%b5%e0%b9%88-6-%e0%b8%8b%e0%b9%89%e0%b8%ad%e0%b8%99-loop/" aria-label="Read more about วิธีใช้ class Template ตอนที่ 6 ซ้อน loop">Read more</a>]]></description>
										<content:encoded><![CDATA[<p><span id="more-229"></span><br />
<strong>หมายเหตุ</strong><br />
เป็นการนำเอา ตอนที่ 3 block (ขั้นสูง) มาแยกให้เห็นตัวอย่างเฉพาะการซ้อน loop</p>
<p><strong>ผลการทำงาน</strong> <a href="http://sixhead.com/run/template/loop-in-loop.php" target="_blank" rel="noopener"><i class="fa fa-external-link"></i></a></p>
<pre class="brush: xml; title: ; notranslate">

&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;วิธีใช้งาน ซ้อน loop&lt;/title&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;module/bootstrap/bootstrap.min.css&quot;&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;div class=&quot;container&quot;&gt;
    &lt;h3&gt;วิธีใช้งาน ซ้อน loop&lt;/h3&gt;
    
    &lt;div class=&quot;alert alert-danger&quot;&gt;        
        &lt;div class=&quot;panel panel-default&quot;&gt;
            &lt;div class=&quot;panel-body&quot;&gt;
                1
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;panel panel-default&quot;&gt;
            &lt;div class=&quot;panel-body&quot;&gt;
                2
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    
    &lt;div class=&quot;alert alert-info&quot;&gt;        
        &lt;div class=&quot;panel panel-default&quot;&gt;
            &lt;div class=&quot;panel-body&quot;&gt;
                1
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;panel panel-default&quot;&gt;
            &lt;div class=&quot;panel-body&quot;&gt;
                2
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    
    &lt;hr&gt;
    
    &lt;div class=&quot;alert alert-success&quot;&gt;
        &lt;div class=&quot;panel panel-default&quot;&gt;
            &lt;div class=&quot;panel-body&quot;&gt;
                1
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;div class=&quot;panel panel-default&quot;&gt;
            &lt;div class=&quot;panel-body&quot;&gt;
                2
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    
    &lt;div class=&quot;alert alert-warning&quot;&gt;
        &lt;div class=&quot;panel panel-default&quot;&gt;
            &lt;div class=&quot;panel-body&quot;&gt;
                1
            &lt;/div&gt;
        &lt;/div&gt;

        &lt;div class=&quot;panel panel-default&quot;&gt;
            &lt;div class=&quot;panel-body&quot;&gt;
                2
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;    

&lt;/div&gt;

&lt;script src=&quot;module/jquery/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;module/bootstrap/bootstrap.min.js&quot;&gt;&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p><strong>_tp_loop-in-loop.html</strong></p>
<pre class="brush: xml; title: ; notranslate">
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;$title&lt;/title&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;module/bootstrap/bootstrap.min.css&quot;&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;div class=&quot;container&quot;&gt;
    &lt;h3&gt;$title&lt;/h3&gt;

    &lt;!--butterfly:items1--&gt;
    &lt;div class=&quot;alert alert-$css&quot;&gt;
        $item
    &lt;/div&gt;
    &lt;!--/butterfly:items1--&gt;

    &lt;hr&gt;

    &lt;!--butterfly:items2--&gt;
    &lt;div class=&quot;alert alert-$css&quot;&gt;
        $item
    &lt;/div&gt;
    &lt;!--/butterfly:items2--&gt;

&lt;/div&gt;

&lt;script src=&quot;module/jquery/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;module/bootstrap/bootstrap.min.js&quot;&gt;&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;

&lt;!--butterfly:item--&gt;
&lt;div class=&quot;panel panel-default&quot;&gt;
    &lt;div class=&quot;panel-body&quot;&gt;
        $no
    &lt;/div&gt;
&lt;/div&gt;
&lt;!--/butterfly:item--&gt;
</pre>
<p><strong>loop-in-loop.php</strong></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
require 'module/SiXhEaD.Template.php';

$tp = new Template('_tp_loop-in-loop.html', 'butterfly');

$title = 'วิธีใช้งาน ซ้อน loop';

$tp-&gt;block('items1');
$styles = &#x5B;'danger', 'info'];
foreach ($styles as $key =&gt; $css) {
    $item = '';
    for ($no = 1; $no &lt; 3; $no++) {
        $item .= $tp-&gt;applyBlock('item');
    }
    $tp-&gt;apply();
}

$tp-&gt;block('items2');
$styles = &#x5B;'success', 'warning'];
foreach ($styles as $key =&gt; $css) {
    $item = '';
    for ($no = 1; $no &lt; 3; $no++) {
        $item .= $tp-&gt;applyBlock('item');
    }
    $tp-&gt;apply();
}

$tp-&gt;display();
exit;
</pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>วิธีใช้ class Template ตอนที่ 5 การใช้งานผ่าน class, function</title>
		<link>https://sixhead.com/%e0%b8%a7%e0%b8%b4%e0%b8%98%e0%b8%b5%e0%b9%83%e0%b8%8a%e0%b9%89-class-template-%e0%b8%95%e0%b8%ad%e0%b8%99%e0%b8%97%e0%b8%b5%e0%b9%88-5-other/</link>
		
		<dc:creator><![CDATA[Chairat Sunthornwiphat]]></dc:creator>
		<pubDate>Fri, 11 Nov 2016 19:06:03 +0000</pubDate>
				<category><![CDATA[Open source]]></category>
		<category><![CDATA[template]]></category>
		<guid isPermaLink="false">http://sixhead.com/?p=170</guid>

					<description><![CDATA[ตอนนี้ได้อะไรบ้าง $tp->setGlobal(false); $tp->setGlobal(true); $tp->assign(); หลักการทำงาน &#8211; เมื่อขนาดโปรเจคท์ใหญ่ขึ้นมีความจำเป็นต้องแยกเป็น class, function ออกมา จะต้องใช้ $tp->setGlobal(false); และตามด้วย $tp->assign(); เพื่อระบุค่าให้ตัวแปร &#8211; มีลักษณะการทำงาน 2 แบบได้แก่ 1. ใช้ $tp->assign(); เฉพาะการแทนค่าใน class, function 2. ใช้ $tp->assign(); ทุกกรณี ผลการทำงาน แบบที่ 1 ผลการทำงาน แบบที่ 2 ทั้ง 2 แบบได้ผลลัพท์เหมือนกัน &#60;!DOCTYPE html&#62; &#60;html&#62; &#60;head&#62; &#60;title&#62;วิธีใช้งาน จาก class, function&#60;/title&#62; &#60;link rel=&#34;stylesheet&#34; href=&#34;module/bootstrap/bootstrap.min.css&#34;&#62; &#60;/head&#62; &#60;body&#62; &#60;div class=&#34;container&#34;&#62; &#60;h3&#62;วิธีใช้งาน จาก ... <a title="วิธีใช้ class Template ตอนที่ 5 การใช้งานผ่าน class, function" class="read-more" href="https://sixhead.com/%e0%b8%a7%e0%b8%b4%e0%b8%98%e0%b8%b5%e0%b9%83%e0%b8%8a%e0%b9%89-class-template-%e0%b8%95%e0%b8%ad%e0%b8%99%e0%b8%97%e0%b8%b5%e0%b9%88-5-other/" aria-label="Read more about วิธีใช้ class Template ตอนที่ 5 การใช้งานผ่าน class, function">Read more</a>]]></description>
										<content:encoded><![CDATA[<p><span id="more-170"></span><br />
<strong>ตอนนี้ได้อะไรบ้าง</strong></p>
<ul>
<li>$tp->setGlobal(false);</li>
<li>$tp->setGlobal(true);</li>
<li>$tp->assign();</li>
</ul>
<p><strong>หลักการทำงาน</strong><br />
&#8211; เมื่อขนาดโปรเจคท์ใหญ่ขึ้นมีความจำเป็นต้องแยกเป็น class, function ออกมา จะต้องใช้ $tp->setGlobal(false); และตามด้วย $tp->assign(); เพื่อระบุค่าให้ตัวแปร<br />
&#8211; มีลักษณะการทำงาน 2 แบบได้แก่<br />
  1. ใช้ $tp->assign(); เฉพาะการแทนค่าใน class, function<br />
  2. ใช้ $tp->assign(); ทุกกรณี</p>
<p><strong>ผลการทำงาน แบบที่ 1</strong> <a href="http://sixhead.com/run/template/other1.php" target="_blank" rel="noopener"><i class="fa fa-external-link"></i></a><br />
<strong>ผลการทำงาน แบบที่ 2</strong> <a href="http://sixhead.com/run/template/other2.php" target="_blank" rel="noopener"><i class="fa fa-external-link"></i></a></p>
<p><strong>ทั้ง 2 แบบได้ผลลัพท์เหมือนกัน</strong></p>
<pre class="brush: xml; title: ; notranslate">
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;วิธีใช้งาน จาก class, function&lt;/title&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;module/bootstrap/bootstrap.min.css&quot;&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;div class=&quot;container&quot;&gt;
    &lt;h3&gt;วิธีใช้งาน จาก class, function&lt;/h3&gt;

    &lt;ul class=&quot;list-group&quot;&gt;    
        &lt;li class=&quot;list-group-item&quot;&gt;1&lt;/li&gt;
        &lt;li class=&quot;list-group-item&quot;&gt;2&lt;/li&gt;
        &lt;li class=&quot;list-group-item&quot;&gt;3&lt;/li&gt;
        &lt;li class=&quot;list-group-item&quot;&gt;4&lt;/li&gt;
        &lt;li class=&quot;list-group-item&quot;&gt;5&lt;/li&gt;
    &lt;/ul&gt;
&lt;/div&gt;

&lt;script src=&quot;module/jquery/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;module/bootstrap/bootstrap.min.js&quot;&gt;&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p><strong>_tp_other.html</strong></p>
<pre class="brush: xml; title: ; notranslate">
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;$title&lt;/title&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;module/bootstrap/bootstrap.min.css&quot;&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;div class=&quot;container&quot;&gt;
    &lt;h3&gt;$title&lt;/h3&gt;

    &lt;ul class=&quot;list-group&quot;&gt;
    &lt;!--SiXhEaD:data--&gt;
        &lt;li class=&quot;list-group-item&quot;&gt;$no&lt;/li&gt;
    &lt;!--/SiXhEaD:data--&gt;
    &lt;/ul&gt;
&lt;/div&gt;

&lt;script src=&quot;module/jquery/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;module/bootstrap/bootstrap.min.js&quot;&gt;&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p><strong>other1.php</strong></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
require 'module/SiXhEaD.Template.php';

$tp = new Template('_tp_other.html');

$title = 'วิธีใช้งาน จาก class, function';
_setData();

$tp-&gt;display();
exit;

function _setData() {
    global $tp;

    $tp-&gt;setGlobal(false);
    $tp-&gt;block('data');
    for ($no = 1; $no &lt; 6; $no++) {
        $tp-&gt;assign('no', $no);
        $tp-&gt;apply();
    }
    $tp-&gt;setGlobal(true);
}
</pre>
<p><strong>other2.php</strong></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
require 'module/SiXhEaD.Template.php';

$tp = new Template('_tp_other.html');
$tp-&gt;setGlobal(false);

$title = 'วิธีใช้งาน จาก class, function';
$tp-&gt;assign('title', $title);
_setData();

$tp-&gt;display();
exit;

function _setData() {
    global $tp;

    $tp-&gt;block('data');
    for ($no = 1; $no &lt; 6; $no++) {
        $tp-&gt;assign('no', $no);
        $tp-&gt;apply();
    }
}
</pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>วิธีใช้ class Template ตอนที่ 4 Memcached</title>
		<link>https://sixhead.com/%e0%b8%a7%e0%b8%b4%e0%b8%98%e0%b8%b5%e0%b9%83%e0%b8%8a%e0%b9%89-class-template-%e0%b8%95%e0%b8%ad%e0%b8%99%e0%b8%97%e0%b8%b5%e0%b9%88-4-memcached/</link>
		
		<dc:creator><![CDATA[Chairat Sunthornwiphat]]></dc:creator>
		<pubDate>Fri, 11 Nov 2016 18:51:58 +0000</pubDate>
				<category><![CDATA[Open source]]></category>
		<category><![CDATA[template]]></category>
		<guid isPermaLink="false">http://sixhead.com/?p=131</guid>

					<description><![CDATA[ตอนนี้ได้อะไรบ้าง cache ทั้งหน้าด้วย Memcached cache บางส่วนด้วย Memcached $tp->generate(); $tp->applyBlock(); หลักการทำงาน โดยปกติเราจะแสดงผลลัพท์ออกมาเลยด้วย $tp->display(); หากต้องการใช้งานอย่างอื่น สามารถนำผลลัพท์ที่ได้จาก $tp->generate(); ไปใช้ ในตัวอย่างนี้คือการเก็บลง Memcached ทั้ง 2 ตัวอย่างให้ลองกด reload ถี่ๆ สังเกตุตรงเวลา cache จะเปลี่ยนใหม่ทุก 5 วินาที ผลการทำงาน 1 (cache ทั้งหน้า) ผลการทำงาน 2 (cache บางส่วน) _tp_memcached.html &#60;!DOCTYPE html&#62; &#60;html&#62; &#60;head&#62; &#60;title&#62;$title&#60;/title&#62; &#60;link rel=&#34;stylesheet&#34; href=&#34;module/bootstrap/bootstrap.min.css&#34;&#62; &#60;/head&#62; &#60;body&#62; &#60;div class=&#34;container&#34;&#62; &#60;h3&#62;$now&#60;/h3&#62; &#60;ul class=&#34;list-group&#34;&#62; $data &#60;!--SiXhEaD:data--&#62;&#60;li class=&#34;list-group-item&#34;&#62;$no. ... <a title="วิธีใช้ class Template ตอนที่ 4 Memcached" class="read-more" href="https://sixhead.com/%e0%b8%a7%e0%b8%b4%e0%b8%98%e0%b8%b5%e0%b9%83%e0%b8%8a%e0%b9%89-class-template-%e0%b8%95%e0%b8%ad%e0%b8%99%e0%b8%97%e0%b8%b5%e0%b9%88-4-memcached/" aria-label="Read more about วิธีใช้ class Template ตอนที่ 4 Memcached">Read more</a>]]></description>
										<content:encoded><![CDATA[<p><span id="more-131"></span><br />
<strong>ตอนนี้ได้อะไรบ้าง</strong></p>
<ul>
<li>cache ทั้งหน้าด้วย Memcached</li>
<li>cache บางส่วนด้วย Memcached</li>
<li>$tp->generate();</li>
<li>$tp->applyBlock();</li>
</ul>
<p><strong>หลักการทำงาน</strong><br />
โดยปกติเราจะแสดงผลลัพท์ออกมาเลยด้วย $tp->display(); หากต้องการใช้งานอย่างอื่น<br />
สามารถนำผลลัพท์ที่ได้จาก $tp->generate(); ไปใช้ ในตัวอย่างนี้คือการเก็บลง Memcached </p>
<p>ทั้ง 2 ตัวอย่างให้ลองกด reload ถี่ๆ สังเกตุตรงเวลา cache จะเปลี่ยนใหม่ทุก 5 วินาที<br />
<strong>ผลการทำงาน 1 (cache ทั้งหน้า)</strong> <a href="http://sixhead.com/run/template/memcached1.php" target="_blank" rel="noopener"><i class="fa fa-external-link"></i></a><br />
<strong>ผลการทำงาน 2 (cache บางส่วน)</strong> <a href="http://sixhead.com/run/template/memcached2.php" target="_blank" rel="noopener"><i class="fa fa-external-link"></i></a></p>
<p><strong>_tp_memcached.html</strong></p>
<pre class="brush: xml; title: ; notranslate">
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;$title&lt;/title&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;module/bootstrap/bootstrap.min.css&quot;&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;div class=&quot;container&quot;&gt;
    &lt;h3&gt;$now&lt;/h3&gt;

    &lt;ul class=&quot;list-group&quot;&gt;
    $data
    &lt;!--SiXhEaD:data--&gt;&lt;li class=&quot;list-group-item&quot;&gt;$no. $now&lt;/li&gt;
    &lt;!--/SiXhEaD:data--&gt;
    &lt;/ul&gt;
&lt;/div&gt;

&lt;script src=&quot;module/jquery/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;module/bootstrap/bootstrap.min.js&quot;&gt;&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p><strong>memcached1.php</strong></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
require 'module/SiXhEaD.Template.php';

$mem = new Memcached();
$mem-&gt;addServer('127.0.0.1', 0000);

$cache_name = &quot;test1&quot;;
$cache = $mem-&gt;get($cache_name);
if (!$cache) {
    $tp = new Template('_tp_memcached.html');

    $title = 'วิธีใช้งานกับ Memcached1';
    $now = date('Y-m-d H:i:s');

    $tp-&gt;block('data');
    for ($no = 1; $no &lt; 6; $no++) {
        $tp-&gt;apply();
    }

    $cache = $tp-&gt;generate();
    $mem-&gt;set($cache_name, $cache, 5);
}

echo $cache;
exit;
</pre>
<p><strong>memcached2.php</strong></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
require 'module/SiXhEaD.Template.php';

$mem = new Memcached();
$mem-&gt;addServer('127.0.0.1', 0000);

$tp = new Template('_tp_memcached.html');

$title = 'วิธีใช้งานกับ Memcached2';
$now = date('Y-m-d H:i:s');

$cache_name = &quot;test2&quot;;
$data = $mem-&gt;get($cache_name);
if (!$data) {
    for ($no = 1; $no &lt; 6; $no++) {
        $data .= $tp-&gt;applyBlock('data');
    }
    $mem-&gt;set($cache_name, $data, 5);
}

$tp-&gt;display();
exit;
</pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>วิธีใช้ class Template ตอนที่ 3 block (ขั้นสูง)</title>
		<link>https://sixhead.com/%e0%b8%a7%e0%b8%b4%e0%b8%98%e0%b8%b5%e0%b9%83%e0%b8%8a%e0%b9%89-class-template-%e0%b8%95%e0%b8%ad%e0%b8%99%e0%b8%97%e0%b8%b5%e0%b9%88-3-block-advance/</link>
		
		<dc:creator><![CDATA[Chairat Sunthornwiphat]]></dc:creator>
		<pubDate>Fri, 11 Nov 2016 14:02:48 +0000</pubDate>
				<category><![CDATA[Open source]]></category>
		<category><![CDATA[template]]></category>
		<guid isPermaLink="false">http://sixhead.com/?p=135</guid>

					<description><![CDATA[ตอนนี้ได้อะไรบ้าง นำข้อมูลใน block จากคนละ template มาใช้งาน เปลี่ยนข้อความกำหนด block แทนคำว่า SiXhEaD sub block sub block คืออะไร sub block เป็นส่วนย่อยภายใน block เหมาะสำหรับ layout ที่แตกต่างกัน เช่นบาง sub block มี 1 รูป บาง sub block มี 2 รูป หรือมี background คนละสี หมายเหตุ &#8211; ในการใช้งานจริงการรวมหรือแยก template ควรคำนึงถึงความเหมาะสมด้วย ไม่ควรแยกมากจนเกินไป ยิ่งเยอะจะกลายเป็นการ open file เกินความจำเป็น &#8211; อยากใช้ข้อความกำหนด block แทนคำว่า SiXhEaD ก็ยังได้ ให้สังเกตุ parameter ... <a title="วิธีใช้ class Template ตอนที่ 3 block (ขั้นสูง)" class="read-more" href="https://sixhead.com/%e0%b8%a7%e0%b8%b4%e0%b8%98%e0%b8%b5%e0%b9%83%e0%b8%8a%e0%b9%89-class-template-%e0%b8%95%e0%b8%ad%e0%b8%99%e0%b8%97%e0%b8%b5%e0%b9%88-3-block-advance/" aria-label="Read more about วิธีใช้ class Template ตอนที่ 3 block (ขั้นสูง)">Read more</a>]]></description>
										<content:encoded><![CDATA[<p><span id="more-135"></span><br />
<strong>ตอนนี้ได้อะไรบ้าง</strong></p>
<ul>
<li>นำข้อมูลใน block จากคนละ template มาใช้งาน</li>
<li>เปลี่ยนข้อความกำหนด block แทนคำว่า SiXhEaD</li>
<li>sub block</li>
</ul>
<p><strong>sub block คืออะไร</strong><br />
sub block เป็นส่วนย่อยภายใน block เหมาะสำหรับ layout ที่แตกต่างกัน เช่นบาง sub block มี 1 รูป บาง sub block มี 2 รูป หรือมี background คนละสี</p>
<p><strong>หมายเหตุ</strong><br />
&#8211; ในการใช้งานจริงการรวมหรือแยก template ควรคำนึงถึงความเหมาะสมด้วย ไม่ควรแยกมากจนเกินไป ยิ่งเยอะจะกลายเป็นการ open file เกินความจำเป็น<br />
&#8211; อยากใช้ข้อความกำหนด block แทนคำว่า SiXhEaD ก็ยังได้ ให้สังเกตุ parameter ที่ 2<br />
$tp_item = new Template(&#8216;_tp_item.html&#8217;, &#8216;Thailand&#8217;);</p>
<p><strong>ผลการทำงาน 1 ($member == 1)</strong> <a href="http://sixhead.com/run/template/block-advance.php?member=1" target="_blank" rel="noopener"><i class="fa fa-external-link"></i></a><br />
<strong>ผลการทำงาน 2 ($member == 0)</strong> <a href="http://sixhead.com/run/template/block-advance.php" target="_blank" rel="noopener"><i class="fa fa-external-link"></i></a></p>
<p><strong>_tp_item.html</strong></p>
<pre class="brush: xml; title: ; notranslate">&lt;!--Thailand:message-member-0--&gt;
&lt;div class=&quot;alert alert-danger&quot;&gt;$ip ไม่สามารถใช้งานได้&lt;/div&gt;
&lt;!--/Thailand:message-member-0--&gt;

&lt;!--Thailand:message-member-1--&gt;
&lt;div class=&quot;alert alert-info&quot;&gt;ยินดีต้อนรับ $username&lt;/div&gt;
&lt;!--/Thailand:message-member-1--&gt;

&lt;!--Thailand:items1--&gt;
$item1_title
&lt;ul class=&quot;list-group&quot;&gt;
    &lt;!--Thailand:item1--&gt;
    &lt;li class=&quot;list-group-item&quot;&gt;$no&lt;/li&gt;
    &lt;!--/Thailand:item1--&gt;
&lt;/ul&gt;
&lt;!--/Thailand:items1--&gt;

&lt;!--Thailand:item2--&gt;
&lt;div class=&quot;alert alert-$css&quot;&gt;$css_uc&lt;/div&gt;
&lt;!--/Thailand:item2--&gt;

&lt;!--Thailand:items3--&gt;
$item3_title
&lt;div class=&quot;row&quot;&gt;
&lt;!--Thailand:item3--&gt;
&lt;!--sub:1--&gt;&lt;div class=&quot;col-md-4&quot;&gt;&lt;div class=&quot;alert alert-success&quot;&gt;$no&lt;/div&gt;&lt;/div&gt;
&lt;!--/sub:1--&gt;
&lt;!--sub:2--&gt;&lt;div class=&quot;col-md-4&quot;&gt;&lt;div class=&quot;alert alert-warning&quot;&gt;$no&lt;/div&gt;&lt;/div&gt;
&lt;!--/sub:2--&gt;
&lt;!--sub:3--&gt;&lt;div class=&quot;col-md-4&quot;&gt;&lt;div class=&quot;alert alert-danger&quot;&gt;$no&lt;/div&gt;&lt;/div&gt;
&lt;!--/sub:3--&gt;
&lt;!--/Thailand:item3--&gt;
&lt;/div&gt;
&lt;!--/Thailand:items3--&gt;
</pre>
<p><strong>_tp_block-advance.html</strong></p>
<pre class="brush: xml; title: ; notranslate">
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;$title&lt;/title&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;module/bootstrap/bootstrap.min.css&quot;&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;div class=&quot;container&quot;&gt;
    &lt;h3&gt;$title&lt;/h3&gt;
    $raw
    $message
    $item1
    $item2_title
    $item2
    $item3
    $item4_title
    &lt;div class=&quot;row&quot;&gt;
    &lt;!--SiXhEaD:item4--&gt;
    &lt;!--sub:1--&gt;&lt;div class=&quot;col-md-4&quot;&gt;&lt;div class=&quot;alert alert-success&quot;&gt;$no&lt;/div&gt;&lt;/div&gt;
    &lt;!--/sub:1--&gt;
    &lt;!--sub:2--&gt;&lt;div class=&quot;col-md-4&quot;&gt;&lt;div class=&quot;alert alert-warning&quot;&gt;$no&lt;/div&gt;&lt;/div&gt;
    &lt;!--/sub:2--&gt;
    &lt;!--sub:3--&gt;&lt;div class=&quot;col-md-4&quot;&gt;&lt;div class=&quot;alert alert-danger&quot;&gt;$no&lt;/div&gt;&lt;/div&gt;
    &lt;!--/sub:3--&gt;
    &lt;!--/SiXhEaD:item4--&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script src=&quot;module/jquery/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;module/bootstrap/bootstrap.min.js&quot;&gt;&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p><strong>block-advance.php</strong></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
require 'module/SiXhEaD.Template.php';

$member = (int) $_GET&#x5B;'member'];

$tp = new Template('_tp_block-advance.html');
$tp_item = new Template('_tp_item.html', 'Thailand');

$title = 'วิธีใช้งาน block (ขั้นสูง)';

if ($member == 1) {
    $username = 'admin';
    $raw = $tp_item-&gt;blockHtml('message-member-1');
    $message = $tp_item-&gt;applyBlock('message-member-1');

    // loop วิธีที่ 1
    $item1_title = 'หัวข้อ 1';
    $tp_item-&gt;block('item1');
    for ($no = 1; $no &lt; 4; $no++) {
        $tp_item-&gt;apply();
    }
    $item1 = $tp_item-&gt;generate();
    $tp_item-&gt;clear('item1'); // จำเป็นหากเรียกจาก template อื่น

    // loop วิธีที่ 2
    $item2_title = 'หัวข้อ 2';
    $styles = &#x5B;'success', 'info', 'warning', 'danger'];
    foreach ($styles as $key =&gt; $css) {
        $css_uc = ucfirst($css);
        $item2 .= $tp_item-&gt;applyBlock('item2');
    }
} else {
    $ip = $_SERVER&#x5B;'REMOTE_ADDR'];
    $raw = $tp_item-&gt;blockHtml('message-member-0');
    $message = $tp_item-&gt;applyBlock('message-member-0');
}

$item3_title = 'หัวข้อ 3';
$tp_item-&gt;block('item3');
$tp_item-&gt;sub(3);
for ($no = 1; $no &lt; 9; $no++) {
    $tp_item-&gt;apply();
}
$item3 = $tp_item-&gt;generate();
$tp_item-&gt;clear('item3'); // จำเป็นหากเรียกจาก template อื่น

$item4_title = 'หัวข้อ 4';
$tp-&gt;block('item4');
$tp-&gt;sub(3);
for ($no = 1; $no &lt; 9; $no++) {
    $tp-&gt;apply();
}

$tp-&gt;display();
exit;
</pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>วิธีใช้ class Template ตอนที่ 2 block (ขั้นต้น)</title>
		<link>https://sixhead.com/%e0%b8%a7%e0%b8%b4%e0%b8%98%e0%b8%b5%e0%b9%83%e0%b8%8a%e0%b9%89-class-template-%e0%b8%95%e0%b8%ad%e0%b8%99%e0%b8%97%e0%b8%b5%e0%b9%88-2-block-simple/</link>
		
		<dc:creator><![CDATA[Chairat Sunthornwiphat]]></dc:creator>
		<pubDate>Fri, 11 Nov 2016 13:09:31 +0000</pubDate>
				<category><![CDATA[Open source]]></category>
		<category><![CDATA[template]]></category>
		<guid isPermaLink="false">http://sixhead.com/?p=117</guid>

					<description><![CDATA[ตอนนี้ได้อะไรบ้าง รู้จัก block แสดง block ซ่อน block block คืออะไร &#8211; block คือส่วนที่เก็บข้อมูลของตัวมันไว้ใช้งาน ไม่ว่าจะเป็นแสดงผลตามเงื่อนไข, ดึงข้อมูลไปใช้งานต่อ หรือ loop &#60;!--SiXhEaD:block-name--&#62;&#60;syntax&#62;$variable&#60;/syntax&#62;&#60;!--/SiXhEaD:block-name--&#62; &#8211; เนื้อหาใน block เป็นอะไรก็ได้ไม่ว่าจะ text, html, xml, json, js ฯลฯ &#8211; block จะซ่อนโดยอัตโนมัติ ต้องสั่งด้วย $tp->apply(); ก่อนจึงจะแสดงออกมา หลักการทำงาน &#8211; ข้อมูลใน block never-see-me จะไม่ถูกแสดงออกมา &#8211; ข้อมูลใน block firefox, chrome จะแสดงก็ต่อเมื่อใช้ browser แต่ละชนิดเปิดดู พร้อมทั้งแสดงข้อมูล browser ออกมา ผลการทำงาน &#60;!DOCTYPE html&#62; &#60;html&#62; &#60;head&#62; ... <a title="วิธีใช้ class Template ตอนที่ 2 block (ขั้นต้น)" class="read-more" href="https://sixhead.com/%e0%b8%a7%e0%b8%b4%e0%b8%98%e0%b8%b5%e0%b9%83%e0%b8%8a%e0%b9%89-class-template-%e0%b8%95%e0%b8%ad%e0%b8%99%e0%b8%97%e0%b8%b5%e0%b9%88-2-block-simple/" aria-label="Read more about วิธีใช้ class Template ตอนที่ 2 block (ขั้นต้น)">Read more</a>]]></description>
										<content:encoded><![CDATA[<p><span id="more-117"></span><br />
<strong>ตอนนี้ได้อะไรบ้าง</strong></p>
<ul>
<li>รู้จัก block</li>
<li>แสดง block</li>
<li>ซ่อน block</li>
</ul>
<p><strong>block คืออะไร</strong><br />
&#8211; block คือส่วนที่เก็บข้อมูลของตัวมันไว้ใช้งาน ไม่ว่าจะเป็นแสดงผลตามเงื่อนไข, ดึงข้อมูลไปใช้งานต่อ หรือ loop</p>
<pre class="brush: xml; title: ; notranslate">&lt;!--SiXhEaD:block-name--&gt;&lt;syntax&gt;$variable&lt;/syntax&gt;&lt;!--/SiXhEaD:block-name--&gt;</pre>
<p>&#8211; เนื้อหาใน block เป็นอะไรก็ได้ไม่ว่าจะ text, html, xml, json, js ฯลฯ<br />
&#8211; block จะซ่อนโดยอัตโนมัติ ต้องสั่งด้วย $tp->apply(); ก่อนจึงจะแสดงออกมา</p>
<p><strong>หลักการทำงาน</strong><br />
&#8211; ข้อมูลใน block never-see-me จะไม่ถูกแสดงออกมา <!--SiXhEaD:never-see-me--><!--/SiXhEaD:never-see-me--><br />
&#8211; ข้อมูลใน block firefox, chrome จะแสดงก็ต่อเมื่อใช้ browser แต่ละชนิดเปิดดู พร้อมทั้งแสดงข้อมูล browser ออกมา</p>
<p><strong>ผลการทำงาน</strong> <a href="http://sixhead.com/run/template/block.php" target="_blank" rel="noopener"><i class="fa fa-external-link"></i></a></p>
<pre class="brush: xml; title: ; notranslate">
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;วิธีใช้งาน block&lt;/title&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;module/bootstrap/bootstrap.min.css&quot;&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;div class=&quot;container&quot;&gt;
    &lt;h3&gt;วิธีใช้งาน block (ขั้นต้น)&lt;/h3&gt;
    
    &lt;div class=&quot;panel panel-warning&quot;&gt;
        &lt;div class=&quot;panel-heading&quot;&gt;สวัสดี Firefox&lt;/div&gt;
        &lt;div class=&quot;panel-body&quot;&gt;Mozilla/5.0 (Windows NT 6.1; WOW64; rv:49.0) Gecko/20100101 Firefox/49.0&lt;/div&gt;
    &lt;/div&gt;    

    &lt;ul class=&quot;list-group&quot;&gt;   
        &lt;li class=&quot;list-group-item &quot;&gt;1&lt;/li&gt;
        &lt;li class=&quot;list-group-item &quot;&gt;2&lt;/li&gt;
        &lt;li class=&quot;list-group-item active&quot;&gt;3&lt;/li&gt;
        &lt;li class=&quot;list-group-item &quot;&gt;4&lt;/li&gt;
        &lt;li class=&quot;list-group-item &quot;&gt;5&lt;/li&gt;
    &lt;/ul&gt;

    &lt;div class=&quot;row&quot;&gt;
        &lt;div class=&quot;col-md-3&quot;&gt;&lt;div class=&quot;alert alert-success&quot;&gt;Success&lt;/div&gt;&lt;/div&gt;
        &lt;div class=&quot;col-md-3&quot;&gt;&lt;div class=&quot;alert alert-info&quot;&gt;Info&lt;/div&gt;&lt;/div&gt;
        &lt;div class=&quot;col-md-3&quot;&gt;&lt;div class=&quot;alert alert-warning&quot;&gt;Warning&lt;/div&gt;&lt;/div&gt;
        &lt;div class=&quot;col-md-3&quot;&gt;&lt;div class=&quot;alert alert-danger&quot;&gt;Danger&lt;/div&gt;&lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script src=&quot;module/jquery/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;module/bootstrap/bootstrap.min.js&quot;&gt;&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p><strong>_tp_block.html</strong></p>
<pre class="brush: xml; title: ; notranslate">
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;$title&lt;/title&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;module/bootstrap/bootstrap.min.css&quot;&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;div class=&quot;container&quot;&gt;
    &lt;h3&gt;$title&lt;/h3&gt;
    
    &lt;!--SiXhEaD:firefox--&gt;
    &lt;div class=&quot;panel panel-warning&quot;&gt;
        &lt;div class=&quot;panel-heading&quot;&gt;สวัสดี Firefox&lt;/div&gt;
        &lt;div class=&quot;panel-body&quot;&gt;$user_agent&lt;/div&gt;
    &lt;/div&gt;
    &lt;!--/SiXhEaD:firefox--&gt;

    &lt;!--SiXhEaD:chrome--&gt;
    &lt;div class=&quot;panel panel-info&quot;&gt;
        &lt;div class=&quot;panel-heading&quot;&gt;สวัสดี Chrome&lt;/div&gt;
        &lt;div class=&quot;panel-body&quot;&gt;$user_agent&lt;/div&gt;
    &lt;/div&gt;
    &lt;!--/SiXhEaD:chrome--&gt;

    &lt;!--SiXhEaD:never-see-me--&gt;
    &lt;div&gt;คุณจะไม่เห็นข้อความนี้&lt;/div&gt;
    &lt;!--/SiXhEaD:never-see-me--&gt;

    &lt;ul class=&quot;list-group&quot;&gt;
        &lt;!--SiXhEaD:data1--&gt;
        &lt;li class=&quot;list-group-item $active&quot;&gt;$no&lt;/li&gt;
        &lt;!--/SiXhEaD:data1--&gt;
    &lt;/ul&gt;

    &lt;div class=&quot;row&quot;&gt;
        &lt;!--SiXhEaD:data2--&gt;
        &lt;div class=&quot;col-md-3&quot;&gt;&lt;div class=&quot;alert alert-$css&quot;&gt;$css_uc&lt;/div&gt;&lt;/div&gt;
        &lt;!--/SiXhEaD:data2--&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script src=&quot;module/jquery/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;module/bootstrap/bootstrap.min.js&quot;&gt;&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p><strong>block.php</strong></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
require 'module/SiXhEaD.Template.php';

$tp = new Template('_tp_block.html');

$title = 'วิธีใช้งาน block (ขั้นต้น)';

$tp-&gt;block('data1');
for ($no = 1; $no &lt; 6; $no++) {
    $active = '';
    if ($no == 3) {
        $active = 'active';
    }
    $tp-&gt;apply();
}

$styles = &#x5B;'success', 'info', 'warning', 'danger'];
$tp-&gt;block('data2');
foreach ($styles as $key =&gt; $css) {
    $css_uc = ucfirst($css);
    $tp-&gt;apply();
}

$user_agent = $_SERVER&#x5B;'HTTP_USER_AGENT'];
if (preg_match('@Firefox@', $user_agent)) {
    $tp-&gt;block('firefox');
    $tp-&gt;apply();
} elseif (preg_match('@Chrome@', $user_agent)) {
    $tp-&gt;block('chrome');
    $tp-&gt;apply();
}

$tp-&gt;display();
exit;
</pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>วิธีใช้ class Template ตอนที่ 1</title>
		<link>https://sixhead.com/%e0%b8%a7%e0%b8%b4%e0%b8%98%e0%b8%b5%e0%b9%83%e0%b8%8a%e0%b9%89-class-template-%e0%b8%95%e0%b8%ad%e0%b8%99%e0%b8%97%e0%b8%b5%e0%b9%88-1/</link>
		
		<dc:creator><![CDATA[Chairat Sunthornwiphat]]></dc:creator>
		<pubDate>Fri, 11 Nov 2016 12:18:03 +0000</pubDate>
				<category><![CDATA[Open source]]></category>
		<category><![CDATA[template]]></category>
		<guid isPermaLink="false">http://sixhead.com/?p=108</guid>

					<description><![CDATA[ตอนนี้ได้อะไรบ้าง แสดงค่าจากตัวแปร แสดงค่าใน block (loop) ข้ามการแทนค่าตัวแปร หมายเหตุ ทุกตอนหากคลิกดูผลการทำงานและ view source จะเห็นว่ามีบรรทัดว่างเยอะ เนื่องจากไฟล์ template ตัวอย่างต้องการให้อ่านง่าย ในการทำงานจริงจะเว้นบรรทัดเท่าที่จำเป็น (งานจริงจะ extends class ล้างบรรทัด และช่องว่างที่ไม่จำเป็นทิ้ง) หลักการทำงาน &#8211; ค้นหาตัวแปร $variable แล้วแทนที่ด้วยค่าที่ต้องการ &#8211; กำหนดไม่ให้แทนค่าด้วยคำสั่ง $tp->ignore(); ผลการทำงาน &#60;!DOCTYPE html&#62; &#60;html&#62; &#60;head&#62; &#60;title&#62;วิธีใช้ class SiXhEaD.Template&#60;/title&#62; &#60;link rel=&#34;stylesheet&#34; href=&#34;module/bootstrap/bootstrap.min.css&#34;&#62; &#60;/head&#62; &#60;body&#62; &#60;div class=&#34;container&#34;&#62; &#60;h3&#62;วิธีใช้ class SiXhEaD.Template&#60;/h3&#62; &#60;ul class=&#34;list-group&#34;&#62; &#60;li class=&#34;list-group-item&#34;&#62;1&#60;/li&#62; &#60;li class=&#34;list-group-item&#34;&#62;2&#60;/li&#62; &#60;li class=&#34;list-group-item&#34;&#62;3&#60;/li&#62; &#60;li ... <a title="วิธีใช้ class Template ตอนที่ 1" class="read-more" href="https://sixhead.com/%e0%b8%a7%e0%b8%b4%e0%b8%98%e0%b8%b5%e0%b9%83%e0%b8%8a%e0%b9%89-class-template-%e0%b8%95%e0%b8%ad%e0%b8%99%e0%b8%97%e0%b8%b5%e0%b9%88-1/" aria-label="Read more about วิธีใช้ class Template ตอนที่ 1">Read more</a>]]></description>
										<content:encoded><![CDATA[<p><span id="more-108"></span><br />
<strong>ตอนนี้ได้อะไรบ้าง</strong></p>
<ul>
<li>แสดงค่าจากตัวแปร</li>
<li>แสดงค่าใน block (loop)</li>
<li>ข้ามการแทนค่าตัวแปร</li>
</ul>
<p><strong>หมายเหตุ</strong><br />
ทุกตอนหากคลิกดูผลการทำงานและ view source จะเห็นว่ามีบรรทัดว่างเยอะ เนื่องจากไฟล์ template ตัวอย่างต้องการให้อ่านง่าย ในการทำงานจริงจะเว้นบรรทัดเท่าที่จำเป็น (งานจริงจะ extends class ล้างบรรทัด และช่องว่างที่ไม่จำเป็นทิ้ง)</p>
<p><strong>หลักการทำงาน</strong><br />
&#8211; ค้นหาตัวแปร $variable แล้วแทนที่ด้วยค่าที่ต้องการ<br />
&#8211; กำหนดไม่ให้แทนค่าด้วยคำสั่ง $tp->ignore();</p>
<p><strong>ผลการทำงาน</strong> <a href="http://sixhead.com/run/template/simple.php" target="_blank" rel="noopener"><i class="fa fa-external-link"></i></a></p>
<pre class="brush: xml; title: ; notranslate">
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;วิธีใช้ class SiXhEaD.Template&lt;/title&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;module/bootstrap/bootstrap.min.css&quot;&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;div class=&quot;container&quot;&gt;
    &lt;h3&gt;วิธีใช้ class SiXhEaD.Template&lt;/h3&gt;

    &lt;ul class=&quot;list-group&quot;&gt;
        &lt;li class=&quot;list-group-item&quot;&gt;1&lt;/li&gt;
        &lt;li class=&quot;list-group-item&quot;&gt;2&lt;/li&gt;
        &lt;li class=&quot;list-group-item&quot;&gt;3&lt;/li&gt;
        &lt;li class=&quot;list-group-item&quot;&gt;4&lt;/li&gt;
        &lt;li class=&quot;list-group-item&quot;&gt;5&lt;/li&gt;
    &lt;/ul&gt;
    
    &lt;div class=&quot;row text-center&quot;&gt;
        &lt;div class=&quot;col-md-3&quot;&gt;$jQuery&lt;/div&gt;
        &lt;div class=&quot;col-md-3&quot;&gt;$1000&lt;/div&gt;
        &lt;div class=&quot;col-md-3&quot;&gt;$library()&lt;/div&gt;
        &lt;div class=&quot;col-md-3&quot;&gt;$$()&lt;/div&gt;
    &lt;/div&gt;

    &lt;div class=&quot;row text-center&quot;&gt;
        &lt;div class=&quot;col-md-3&quot;&gt;&lt;/div&gt;
        &lt;div class=&quot;col-md-3&quot;&gt;&lt;/div&gt;
        &lt;div class=&quot;col-md-3&quot;&gt;&lt;/div&gt;
        &lt;div class=&quot;col-md-3&quot;&gt;&lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script src=&quot;module/jquery/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;module/bootstrap/bootstrap.min.js&quot;&gt;&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p><strong>_tp_simple.html</strong></p>
<pre class="brush: xml; title: ; notranslate">
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;$title&lt;/title&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;module/bootstrap/bootstrap.min.css&quot;&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;div class=&quot;container&quot;&gt;
    &lt;h3&gt;$title&lt;/h3&gt;

    &lt;ul class=&quot;list-group&quot;&gt;
    &lt;!--SiXhEaD:data--&gt;
        &lt;li class=&quot;list-group-item&quot;&gt;$no&lt;/li&gt;
    &lt;!--/SiXhEaD:data--&gt;
    &lt;/ul&gt;
    
    &lt;div class=&quot;row text-center&quot;&gt;
        &lt;div class=&quot;col-md-3&quot;&gt;$jQuery&lt;/div&gt;
        &lt;div class=&quot;col-md-3&quot;&gt;$1000&lt;/div&gt;
        &lt;div class=&quot;col-md-3&quot;&gt;$library()&lt;/div&gt;
        &lt;div class=&quot;col-md-3&quot;&gt;$$()&lt;/div&gt;
    &lt;/div&gt;

    &lt;div class=&quot;row text-center&quot;&gt;
        &lt;div class=&quot;col-md-3&quot;&gt;$var1&lt;/div&gt;
        &lt;div class=&quot;col-md-3&quot;&gt;$var2&lt;/div&gt;
        &lt;div class=&quot;col-md-3&quot;&gt;$var3&lt;/div&gt;
        &lt;div class=&quot;col-md-3&quot;&gt;$var4&lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;script src=&quot;module/jquery/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;module/bootstrap/bootstrap.min.js&quot;&gt;&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p><strong>simple.php</strong></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
require 'module/SiXhEaD.Template.php';

$tp = new Template('_tp_simple.html');

$title = 'วิธีใช้ class SiXhEaD.Template';

$tp-&gt;block('data');
for ($no = 1; $no &lt; 6; $no++) {
    $tp-&gt;apply();
}

$tp-&gt;ignore('jQuery');
$tp-&gt;ignore('1000');
$tp-&gt;ignore('library');

$tp-&gt;display();
exit;
</pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SiXhEaD Template &#8211; PHP Template Engine</title>
		<link>https://sixhead.com/sixhead-template-php-template-engine/</link>
		
		<dc:creator><![CDATA[Chairat Sunthornwiphat]]></dc:creator>
		<pubDate>Thu, 10 Nov 2016 03:36:00 +0000</pubDate>
				<category><![CDATA[Open source]]></category>
		<category><![CDATA[template]]></category>
		<guid isPermaLink="false">http://sixhead.com/?p=39</guid>

					<description><![CDATA[ในยุคที่ PHP เริ่มเป็นที่นิยม การเขียนจะเป็นแบบ PHP + Html ในไฟล์เดียวซึ่งมันดูรก และไม่เป็นระเบียบ ตอนนั้นสลับจากภาษา Perl มา PHP มี function ง่ายๆ อยู่จึงได้แปลง Perl มาเป็น PHP มีไม่กี่บรรทัด (code อยู่ท้ายหน้า) พัฒนาเรื่อยมาจนเป็น class ใช้ถึงตอนนี้ คิดว่าน่าจะมีประโยชน์สำหรับ PHP Programmer จึงได้นำมาให้ลองใช้กัน *สามารถนำไปใช้ได้กับงานทุกประเภทที่คุณต้องการ ทั้งแจกฟรี และการค้า หมายเหตุ &#8211; ข้อดีของการแยกไฟล์ Html ออกมาคือเราจะมองเห็น layout ของ Html แบบที่เป็นอยู่จริง คนเขียน CSS สามารถแก้ และดู layout ได้โดยไม่ต้องเรียกผ่าน PHP &#8211; รองรับ PHP5 และ PHP7 [update ... <a title="SiXhEaD Template &#8211; PHP Template Engine" class="read-more" href="https://sixhead.com/sixhead-template-php-template-engine/" aria-label="Read more about SiXhEaD Template &#8211; PHP Template Engine">Read more</a>]]></description>
										<content:encoded><![CDATA[<p><span id="more-39"></span><br />
ในยุคที่ PHP เริ่มเป็นที่นิยม การเขียนจะเป็นแบบ PHP + Html ในไฟล์เดียวซึ่งมันดูรก และไม่เป็นระเบียบ<br />
ตอนนั้นสลับจากภาษา Perl มา PHP มี function ง่ายๆ อยู่จึงได้แปลง Perl มาเป็น PHP มีไม่กี่บรรทัด (code อยู่ท้ายหน้า)<br />
พัฒนาเรื่อยมาจนเป็น class ใช้ถึงตอนนี้ คิดว่าน่าจะมีประโยชน์สำหรับ PHP Programmer จึงได้นำมาให้ลองใช้กัน<br />
<strong>*สามารถนำไปใช้ได้กับงานทุกประเภทที่คุณต้องการ ทั้งแจกฟรี และการค้า</strong></p>
<p><strong>หมายเหตุ</strong><br />
&#8211; ข้อดีของการแยกไฟล์ Html ออกมาคือเราจะมองเห็น layout ของ Html แบบที่เป็นอยู่จริง คนเขียน CSS สามารถแก้ และดู layout ได้โดยไม่ต้องเรียกผ่าน PHP<br />
&#8211; รองรับ PHP5 และ PHP7</p>
<p>[update 28/12/2016]<br />
<a href="http://sixhead.com/download/SiXhEaD.Template.v6.0.4.zip">SiXhEaD.Template.v6.0.4</a><br />
<a href="http://sixhead.com/download/CodeIgniter.v3.1.2.with.SiXhEaD.Template.v6.0.4.zip">SiXhEaD.Template.v6.0.4 + CodeIgniter.v3.1.2</a><br />
โครงสร้างไฟล์ที่เกี่ยวข้อง CodeIgniter</p>
<pre class="brush: plain; title: ; notranslate">
/application/controllers/Sixhead.php
/application/libraries/Tp.php
/application/libraries/SiXhEaD.Template.php
/application/views/_tp_index.html
/application/views/_tp_item.html
</pre>
<p>วิธีใช้ v5.7 โดย 9AuM scriptdd.com (เก่าแล้ว บาง function อาจมีการเปลี่ยนชื่อ)<br />
<a href="http://scriptdd.com/webtip/sixhead_template_php_template_engine_part1.html">ตอนที่ 1</a> l <a href="http://scriptdd.com/webtip/sixhead_template_php_template_engine_part2.html">ตอนที่ 2</a> l <a href="http://scriptdd.com/webtip/sixhead_template_php_template_engine_part3.html">ตอนที่ 3</a></p>
<p><strong>มือใหม่</strong><br />
เผื่อไม่รู้ห้ามนำไปใช้ แบบ parameter เป็นชื่อไฟล์ตรงๆ เด็ดขาด เป็นเหตุผลด้านความปลอดภัยเรียกว่า <a href="https://www.owasp.org/index.php/Testing_for_Local_File_Inclusion">Local File Inclusion </a></p>
<p>ไม่ควร<br />
page.php?file=home.html<br />
ควร<br />
page.php?file=1<br />
แล้วไปเช็คเงื่อนไข 1 เรียก home.html อีกที</p>
<p><strong>function ต้นแบบ</strong></p>
<p>Perl</p>
<pre class="brush: perl; title: ; notranslate">
sub Template {
    my $HTML=&quot;&quot;;
    open (TEMPLATE, &quot;$template&quot;) || die print &quot;CAN NOT OPEN : $template : $!&quot;;
    while(&lt;TEMPLATE&gt;) { $HTML .= $_; }
    close(TEMPLATE);

    $HTML =~ s/\$(\w+)/${$1}/g;
    print $HTML;
}
</pre>
<p>PHP</p>
<pre class="brush: php; title: ; notranslate">
function Template($template) {
    $fp = fopen($template, &quot;r&quot;);
    $HTML = fread($fp, filesize($template));
    fclose($fp);

    $HTML = preg_replace(&quot;/\\$(\w+)/e&quot;,&quot;$$1&quot;,$HTML); 
    echo $HTML;
}
</pre>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
