如果函数将HTML标记放在PHP中

PHP:

  if (isset($form['preview_message'])) {

    print drupal_render($form['preview_message']);
    print '</div>';
  }

I want like this:

 if (isset($form['preview_message'])) {
      <div class="slide-nav">
            <a href="#"><span id="prev"></span></a>
            <a href="#"><span id="next"></span></a>

        </div>
    print drupal_render($form['preview_message']);
    print '</div>';
  }

I tried but have syntax problems. How can I fix it?

 if (isset($form['preview_message'])) {
   ?>
    <div class="slide-nav">
        <a href="#"><span id="prev"></span></a>
        <a href="#"><span id="next"></span></a>

    </div>
   <?php
print drupal_render($form['preview_message']);
print '</div>';
}

please mark as answer if so, thanks.

Well, you are printing ending using print, maybe you should try that to other html output within our script too?

You need to do one of the following:

Close and re-open your PHP tags

if (isset($form['preview_message'])) {
    ?>
    <div class="slide-nav">
        <a href="#"><span id="prev"></span></a>
        <a href="#"><span id="next"></span></a>

    </div>
    <?php
    print drupal_render($form['preview_message']);
    print '</div>';
}

Print your HTML with PHP

if (isset($form['preview_message'])) {

    print '<div class="slide-nav">
        <a href="#"><span id="prev"></span></a>
        <a href="#"><span id="next"></span></a>

    </div>';

    print drupal_render($form['preview_message']);
    print '</div>';
}

Use the output buffer to store your HTML and print with PHP

if (isset($form['preview_message'])) {

    ob_start();
    ?>
    <div class="slide-nav">
        <a href="#"><span id="prev"></span></a>
        <a href="#"><span id="next"></span></a>

    </div>
    <?php
    print ob_get_clean();

    print drupal_render($form['preview_message']);
    print '</div>';
}

The first option would suite you best

The option you choose is down to your coding style, i personally prefer to print HTML outside of PHP, as I think it's more readable when making changes, but using the output buffer has its advantages if you are re-using the HTML in multiple places (if you store it as a variable rather than printing)

Ore just use "print" again or "echo" :

echo '
    <div class="slide-nav">
        <a href="#"><span id="prev"></span></a>
        <a href="#"><span id="next"></span></a>

    </div>';
echo drupal_render($form['preview_message']);
echo  '</div>';