{"id":76,"date":"2006-11-22T14:55:26","date_gmt":"2006-11-22T14:55:26","guid":{"rendered":"http:\/\/www.rumahweb.com\/journal\/web-template-tanpa-table-php-javascript-dan-css-bagian-4.htm"},"modified":"2006-11-22T14:57:29","modified_gmt":"2006-11-22T14:57:29","slug":"web-template-tanpa-table-php-javascript-dan-css-bagian-4","status":"publish","type":"post","link":"https:\/\/www.rumahweb.com\/journal\/web-template-tanpa-table-php-javascript-dan-css-bagian-4\/","title":{"rendered":"Web Template Tanpa Table &#8211; PHP, JavaScript, dan CSS (Bagian 4)"},"content":{"rendered":"<p>Berikut ini adalah engine yang akan digunakan membaca file template, mengisinya dengan modul-modul dan menampilkan ke web browser.<\/p>\n<p><!--more--><\/p>\n<p>engine.php<\/p>\n<p>[php]<br \/>\nclass Template {<br \/>\nvar $html = &#8220;&#8221;;<\/p>\n<p>function Template($fileTemplate) {<br \/>\n$namaFile = &#8220;$fileTemplate&#8221;;<br \/>\n$penunjukFile = fopen($namaFile, &#8220;r&#8221;);<br \/>\n$this-&gt;html = fread($penunjukFile, filesize($namaFile));<br \/>\nfclose($penunjukFile);<br \/>\n}<\/p>\n<p>function isiVar($namaVar, $isiVar) {<br \/>\n$this-&gt;html = ereg_replace(&#8220;#$namaVar#&#8221;, $isiVar, $this-&gt;html);<br \/>\n}<\/p>\n<p>function isiBlokKiri($modulnya = array()) {<br \/>\n$isiBlokTotal = &#8220;&#8221;;<br \/>\nforeach($modulnya as $kunci =&gt; $nilai) {<br \/>\ninclude_once(&#8220;kiri\/$nilai.php&#8221;);<br \/>\n$isiBlokTotal .= $dt;<br \/>\n}<br \/>\n$this-&gt;html = ereg_replace(&#8220;#BLOCK_KIRI#&#8221;, $isiBlokTotal, $this-&gt;html);<br \/>\n}<\/p>\n<p>function isiContent($modulenya) {<br \/>\ninclude_once(&#8220;content\/$modulenya.php&#8221;);<br \/>\n$this-&gt;html = ereg_replace(&#8220;#CONTENT#&#8221;, $dt, $this-&gt;html);<br \/>\n}<\/p>\n<p>function isiBlokKanan($modulnya = array()) {<br \/>\n$isiBlokTotal = &#8220;&#8221;;<br \/>\nforeach($modulnya as $kunci =&gt; $nilai) {<br \/>\ninclude_once(&#8220;kanan\/$nilai.php&#8221;);<br \/>\n$isiBlokTotal .= $dt;<br \/>\n}<br \/>\n$this-&gt;html = ereg_replace(&#8220;#BLOCK_KANAN#&#8221;, $isiBlokTotal, $this-&gt;html);<br \/>\n}<\/p>\n<p>function tampilkanContent() {<br \/>\necho $this-&gt;html;<br \/>\n}<br \/>\n}<br \/>\n[\/php]<\/p>\n<p>index.php<\/p>\n<p>[php]<br \/>\nerror_reporting(&#8220;E_ERROR&#8221;);<\/p>\n<p>include_once(&#8220;engine.php&#8221;);<\/p>\n<p>$tpl = new Template(&#8216;utama.htm&#8217;);<\/p>\n<p>$content = $_REQUEST[&#8216;content&#8217;];<br \/>\nif (empty($content)) {<br \/>\n$content = &#8216;home&#8217;;<br \/>\n}<\/p>\n<p>$kiri = array(&#8216;menu-vertikal&#8217;, &#8216;kotak-weblogin&#8217;);<br \/>\n$kanan = array(&#8216;polling&#8217;, &#8216;shoutbox&#8217;);<\/p>\n<p>$tpl-&gt;isiVar(&#8216;JUDUL_WEBSITE&#8217;, &#8216;Website Buat Belajar Aja&#8217;);<\/p>\n<p>$tpl-&gt;isiBlokKiri($kiri);<br \/>\n$tpl-&gt;isiContent($content);<br \/>\n$tpl-&gt;isiBlokKanan($kanan);<\/p>\n<p>$tpl-&gt;tampilkanContent();<br \/>\n[\/php]<\/p>\n<p>Silakan di cek lagi susunan file dan direktori adalah sebagai berikut:<\/p>\n<p>index.php<br \/>\nutama.htm<br \/>\ntable.css<br \/>\nengine.php<br \/>\nkiri\/menu-vertikal.php<br \/>\nkiri\/kotak-weblogin.php<br \/>\ncontent\/home.php<br \/>\ncontent\/berita-terbaru.php<br \/>\nkanan\/polling.php<br \/>\nkanan\/shoutbox.php<\/p>\n<p>Selamat mencoba!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Berikut ini adalah engine yang akan digunakan membaca file template, mengisinya dengan modul-modul dan menampilkan ke web browser.<\/p>\n","protected":false},"author":57,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1],"tags":[],"class_list":{"0":"post-76","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-news"},"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p8n3G7-1e","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.rumahweb.com\/journal\/wp-json\/wp\/v2\/posts\/76","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rumahweb.com\/journal\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rumahweb.com\/journal\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rumahweb.com\/journal\/wp-json\/wp\/v2\/users\/57"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rumahweb.com\/journal\/wp-json\/wp\/v2\/comments?post=76"}],"version-history":[{"count":0,"href":"https:\/\/www.rumahweb.com\/journal\/wp-json\/wp\/v2\/posts\/76\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rumahweb.com\/journal\/wp-json\/wp\/v2\/media?parent=76"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rumahweb.com\/journal\/wp-json\/wp\/v2\/categories?post=76"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rumahweb.com\/journal\/wp-json\/wp\/v2\/tags?post=76"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}