简体   繁体   English

在第一个html标记内使用php代码的惯例是什么?

[英]What is this convention of using php code inside the first html tags?

I was referring the page.tpl.php(Drupal 7 theme) for understanding the code. 我指的是page.tpl.php(Drupal 7主题)以了解代码。 I found the following code, 我发现以下代码,

<?php if ($site_name || $site_slogan): ?>
        <!-- !Site name and Slogan -->
        <div<?php print $hgroup_attributes; ?>>

          <?php if ($site_name): ?>
            <h1<?php print $site_name_attributes; ?>><?php print $site_name; ?></h1>
          <?php endif; ?>

          <?php if ($site_slogan): ?>
            <h2<?php print $site_slogan_attributes; ?>><?php print $site_slogan; ?></h2>
          <?php endif; ?>

        </div>
<?php endif; ?>

Can you see the code in third line, <div<?php print $hgroup_attributes; ?>> 您能在第三行<div<?php print $hgroup_attributes; ?>>看到代码<div<?php print $hgroup_attributes; ?>> <div<?php print $hgroup_attributes; ?>> WHY the php code is inside the first div tag of html? <div<?php print $hgroup_attributes; ?>> PHP代码为什么在html的第一个div标签内? Same thing in later part of code also, as you can see h1 and h2 code. 在代码的后半部分也是如此,就像您看到的h1和h2代码一样。 So, what is this convention of combining the html and php in so complicated way? 那么, 以如此复杂的方式组合html和php的约定是什么? and how should I read that? 我应该怎么读?

Combining HTML and PHP code in Drupal templates is actually a very strong feature. 实际上,在Drupal模板中结合HTML和PHP代码是一个非常强大的功能。 In this case, $hgroup_attributes will probably contain some classes that style the div . 在这种情况下, $hgroup_attributes可能包含一些样式为div类。 Printing it in the template results in something like 将其打印在模板中会导致类似

<div class="SOME_CLASSES"> ... </div>

If you're further interested in the variable $hgroup_attributes , you can inspect by pasting <?php dpm($hgroup_attributes); ?> 如果您对变量$hgroup_attributes进一步感兴趣,则可以通过粘贴<?php dpm($hgroup_attributes); ?>检查<?php dpm($hgroup_attributes); ?> <?php dpm($hgroup_attributes); ?> in your template file after you've installed the Devel module. 安装Devel模块后,在模板文件中添加<?php dpm($hgroup_attributes); ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM