문제

First of all, my question may be unclear. I will try to explain it.

this is my html

<div class="left"><?php print $search_box; ?><?php if (!empty($logo)): ?><a href="<?php print $base_path; ?>" title="<?php print t('Home'); ?>" rel="home"><img src="<?php print $logo; ?>" alt="<?php print t('Home'); ?>" id="logo" width="243" height="62" /></a><?php endif; ?><?php if (!empty($site_name)): ?><div id='site-name'><strong><a href="<?php print $base_path; ?>" title="<?php print t('Home'); ?>" rel="home"><?php print $site_name; ?></a></strong></div><?php endif; ?><?php if (!empty($site_slogan)): ?><div id='site-slogan'><?php print $site_slogan; ?></div><?php endif; ?></div>

looks ugly and difficult to debug, right?

so i try to indent and add newline. However, it will fails on some browser, may be IE6. The result is changed. So, What should i go, should i use another doctype?

Currently, i am using

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
도움이 되었습니까?

해결책

You can write it this way too:

<div class="left">
  <?php print $search_box; ?>
    <?php if (!empty($logo)) { ?>
    <a href="<?php print $base_path; ?>" title="<?php print t('Home'); ?>" rel="home">
      <img src="<?php print $logo; ?>" alt="<?php print t('Home'); ?>" id="logo" width="243" height="62" />
    </a>
  <?php } ?>

  <?php if (!empty($site_name)) { ?>
    <div id='site-name'>
      <strong>
      <a href="<?php print $base_path; ?>" title="<?php print t('Home'); ?>" rel="home"><?php print $site_name; ?></a>
      </strong>
    </div>
  <?php } ?>

  <?php if (!empty($site_slogan)) { ?>
    <div id='site-slogan'><?php print $site_slogan; ?></div>
  <?php } ?>
</div>

This should work in most cases, or you can use the php heredoc syntax to echo out the html stuff normally.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top