[英]What is this convention of using php code inside the first html tags?
我指的是page.tpl.php(Drupal 7主题)以了解代码。 我发现以下代码,
<?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; ?>
您能在第三行<div<?php print $hgroup_attributes; ?>>
看到代码<div<?php print $hgroup_attributes; ?>>
<div<?php print $hgroup_attributes; ?>>
PHP代码为什么在html的第一个div标签内? 在代码的后半部分也是如此,就像您看到的h1和h2代码一样。 那么, 以如此复杂的方式组合html和php的约定是什么? 我应该怎么读?
实际上,在Drupal模板中结合HTML和PHP代码是一个非常强大的功能。 在这种情况下, $hgroup_attributes
可能包含一些样式为div
类。 将其打印在模板中会导致类似
<div class="SOME_CLASSES"> ... </div>
如果您对变量$hgroup_attributes
进一步感兴趣,则可以通过粘贴<?php dpm($hgroup_attributes); ?>
检查<?php dpm($hgroup_attributes); ?>
安装Devel模块后,在模板文件中添加<?php dpm($hgroup_attributes); ?>
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.