ThaiBuddyTrip.com - เว็บคู่หูของคนชอบเที่ยว

Full Version: แทรก script หรือ php ลงใน smarty แล้ว error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Smarty เป็น free template engine ครับ ซึ่งการแทรก script จำพวก java script หรือ php จะต้องมี tag คลุม ดังนี้

ถ้าต้องการแทรก java script
Code:
{literal}
<script>โค็ดหรือ script ของเรา</script>
{/literal}

ส่วนรูปแบบโค๊ด php ก็ต้องแทรก tag ดังนี้
Code:
{php}
โค็ดหรือ script ของเรา
{/php}
เช่น
Code:
{php}
echo "This is PHP Code executing directly";
for($i=0; $i<3; $i++)
echo "But it's better to avoid embedding PHP code in your template";
{/php}
ขอบคุณครับ ตอนนี้ผมก้อปรับแต่งเว็บที่ผมทำอยู่ให้เป็นแบบ smarty เกือบจะหมดแหละครับ เหลืออีกไม่กี่เว็บครับ ซึ่งลองเล่นดูแล้ว การทำการแก้ไข ไฟล์ต่าง ๆ สามารถทำได้ง่าย กว่าการเขียนแบบเดิมมากครับ แยก โค้ดกันเลยระหว่าง html และ php หรือ การออกแบบ กราฟิก และ การเขียน สคิปต์
Reference URL's