node

How to get the path of your theme

เวลาอยากจะดึง path ของ theme มาใช่เพื่อวัตถุประสงค์บางประการ เช่น link รูปหรืออะไรก็ตามแต่ ทำได้ดังนี้

ใช้งานใน template file (.tpl.php)
$directory สามารถใช้ได้ในทุก .tpl.php

ถ้าอยู่ใน module หรือ theme helper function
path_to_theme() จะให้ผลลัพธ์เดียวกับ $directory
base_path() จะให้ root url path ของ website

เสริมอีกเล็กน้อยถ้าอยากได้ Path ของฝั่ง Server ใช้นี่เลย !!
realpath(".").'/sites/'
ผลลัพธ์ /var/www/domain.com/sites/

drupal_get_path($type,$name) // use db
dirname(__FILE__); // for high performance doesn't touch any db

Comments

คนแปลกหน้า's picture

แว่บแรกนึ

แว่บแรกนึกว่า wordpress ซะอีก ดูไปดูมา dp นิ ก็ดูดีแหะ

พอดีหลงเข้ามาครับ
เห็นชื่อคุ้นๆ แล้วก็ใช่จริงๆด้วย (เคยติดตามผลงาน hunt ตั้งแต่สมัยโบราณมาแล้ว)

เนื้อหาในบล๊อคก็น่าสนใจดีครับ เดี๊ยว bookmark ไว้ :D

คนแปลกหน้า's picture

กำลังหา

กำลังหา วิธี ดูพอดีเลย

คนแปลกหน้า's picture

รอโพสใหม่

รอโพสใหม่อยู่ครับ :P

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account, used to display your avatar.