PHP syntax in Movable Type dynamic publishing

in Movable Type

When I published my sites powered by Movable Type statically, I can easily include a PHP syntax in the body or extended entry field. Using this kind of method, I can easily put a certain file to be displayed in a certain post (pages or regular posts).

For example, in my contact page. I just create a single post and in the body field, I just put something like <?php include("/path/to/contact-form.php"); ?>. So, when I need to modify the contact form, I only need to edit the contact-form.php file.

But, when I tried to switch to dynamic publishing, it does not work. Luckily, Brad Choate gave a solution. Thanks Brad! He helped me few months ago.


We need to change my template. Because I want to be able to include PHP syntax in my entry body, the only thing I need to is modify the reqular <$MTEntryBody$> into:

<?php
$body = $this->tag('MTEntryBody');
if (preg_match('/<\?php/', $body))
$body = eval('?' . '>' . $body);
echo $body;
?>

From now on, I can include PHP syntax in my post when my weblog published dynamically.

If you're new here, you may want to subscribe to my RSS feed go get the latest entry from your RSS reader. You can also have my contents delivered to your inbox.

This entry receives 3 comments.

  1. Me

    Thanks for the tip!

    Dec 7, 2006 at 10:07 am

  2. kus

    wah kupikir post color identify fi samping kiri adalah mirip dengan shauninman.com/post the heap :D, ternyata di buat sesuai dengan ciri post ya :D

    untuk post asli di beri warna coklat tua, untuk bookmarks di kasih warna hijau :D he he he :D

    secara gw bukan pengguna MT , maka sepertinya aye gak butuh tips itu, tapi … thanks dah :D

    Dec 7, 2006 at 4:04 pm

  3. Thomas Arie

    Wah, beda mas. Yang samping itu sederhana saja… benar memang, itu berdasar tipe post.. journal entry sama bookmark. Hehehe… ya, iseng-iseng saja sih.. :D

    Nah, memang ini untuk MT perlu perlakuan khusus. Tapi Textpattern sepertinya malah lebih memberikan kemudahan untuk melakukan apa yang saya maksudnya.. Ya, sebagai mantan murid Textpattern… hihihihi

    Dec 8, 2006 at 12:39 pm

Orangescale Podcast

If you like podcast, I also have my own podcast station (in English, Bahasa Indonesia, even Javanese language!)
Visit podcast page

Orangescale Video Blogging

Using my digital camera and also mobile device, I document interesting stuff on the street.
Check out my videoblogging

Subscribe

Buy me coffee

Do you like articles and other in my blog? If you find them useful, you can support me by sending donation.