WordPress.org

Support

Support » Requests and Feedback » <?php echo … ?> a better way?

<?php echo … ?> a better way?

  • I just undertook my first project using WordPress. I must admit it’s a bit jarring returning to PHP after over a year of Ruby (but that’s a different topic…).

    One thing I am struck by is the sheer amount of HTML mixed with code. This seems a recipe for broken markup. To that end, I’ve created a small DSL (kinda) that should create correct XHTML markup via PHP. Example usage:

    <?php
    $x = new Xhtml('div', null, Array('class' => 'wrapper'));
    $img = $x->add('img', null, Array('src' => 'zoo.jpg'));
    $ul = $x->add('ul');
    foreach($foos as $foo) {
    $ul->add_with_text('li', $foo);
    }
    echo $x->to_html();
    ?>

    Note that I didn’t have to close any (X)HTML tags or worry about whether the tag was self-closing? Yeah.

    My question is this: Would anyone use such a magic tool? If so, I’ll post it.

Viewing 1 replies (of 1 total)
  • I guess it’s just personal choice. I personally prefer stepping in and out of PHP rather than using a template system like Smarty or something. It’s so much less work and I very rarely make invalid XHTML.

    But of course WordPress is pretty damn flexible, so you can do as you please.

Viewing 1 replies (of 1 total)
  • The topic ‘<?php echo … ?> a better way?’ is closed to new replies.