W3C验证错误'文档类型不允许元素“链接”这里'

时间:2013-06-20 11:27:12

标签: html smarty w3c w3c-validation

我使用两个文件显示我的网页一个用于页眉和页脚(layout.htm)和内容(content.htm)使用smarty我包含文件 例如: layout.htm

<html> 
   <head> 
      //here i am adding script and styles its common for all page 
   </head>
   <body>
   <div class="body">
      {include file=$INNER_PAGE}        
   </div>
</body>
</html>

我需要在内部页面中单独包含样式,该样式应仅针对该页面,因此我无法将其添加到layout.htm中。所以我将以下行包含在我的content.htm文件中

<link rel="stylesheet" type="text/css" href="prop_descr.css"/>

因为它显示错误所以我怎么能解决这个问题

谢谢你!

2 个答案:

答案 0 :(得分:1)

只需在layout.htm模板中的head标记内添加条件:

{if $extra_css}
<link rel="stylesheet" type="text/css" href="{$extra_css}"/>
{/if}

然后将php中的文件名分配给变量:

$smarty->assign('extra_css', 'prop_descr.css');

编辑:如果您需要使用多个,请使用数组并循环遍历它:

PHP:

$smarty->assign('extra_css', array('prop_descr.css','another.css','another_one.css'));

smarty的:

{foreach from=$extra_css item=css_path}
  <link rel="stylesheet" type="text/css" href="{$css_path}"/>
{/foreach}

答案 1 :(得分:0)

根据HTML规范,您无法在link元素中使用body元素。您应该安排一些事情,以便link元素出现在head元素中。在给定的上下文中,您可以通过省略div class=body标记(虽然省略它可能需要更改CSS代码)以及</head>和{{1}来实现此目的。 }标签。但是,可能有更聪明的方法来实现这一目标。