我已经遇到了这个问题: 我有一个Drupal模块,它将使用ECHO长HTML代码。 (我刚刚开始使用Drupal模块)。 我似乎无法找到将CSS添加到此页面的方法。
这是我的模块:
<?php
function kartta_help($path, $args) {
if ($path == 'admin/help#kartta') {
return t("<h1>kartta modulin dokumentaatio</h1>
</br>tänne tulee karttamodulin dokumentaatio");
}
}
function kartta_menu() {
$items = array();
$items['kartta_module/kartta'] = array(
'title' => 'Karttamodule',
'page callback' => 'say_kartta',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
return $items;
}
function say_kartta() {
echo '
<head>
<meta charset=utf-8>
<meta name="viewport" content="width=620">
<title>maps form</title>
<link rel="stylesheet" href="form.css">
<script src="scripts/form.js"></script>
</head>
<div id=header>
<h1>Form</h1>
<h2>Upload a new map or choose an existing one.</h2>
</div>
<div id=selection>
<button id=btnNew>New</button>
<button id=btnEdit>Edit</button>
</div>
<div id=new>
<br />
<form name=newMapForm action="scripts/fallback/uploadDeleteImage.php" method=POST enctype="multipart/form-data">
Choose a file to upload: <input name="map" id="inputImage" type="file" required/><br />
Give the map a name: <input type="text" name="name" id="inputName" required/> <br />
<input type="submit" value="Upload" id="btnUpload" name="upload"/>
</form>
<br />
</div>
<div id=edit>
<br />
Choose a file to edit:
<select id=mapSelect>
</select>
<br />
<div id=afterSelect>
<p id="selectedMapName"></p>
<img alt="map" id="selectedMapImage"/>
<form name="editMapForm" action="edit.php" method="POST">
<input id="hiddenNameEdit" type="hidden" name="name" value=""/>
<input id="hiddenPathEdit" type="hidden" name="path" value=""/>
<input type="submit" value="Edit" id="btnEdit" name="edit"/>
</form>
<form name="deleteMapForm" action="scripts/fallback/uploadDeleteImage.php" method="POST" id="frmDeleteMap">
<input id="hiddenNameDelete" type="hidden" name="name" value=""/>
<input id="hiddenPathDelete" type="hidden" name="path" value=""/>
<input type="submit" value="Delete" id="btnDelete" name="delete"/>
</form>
</div>
<br />
</div>
';
}
观看或阅读并不漂亮,但是只通过阅读它的开头就能明白这一点。 .info文件:
name = kartta module
description = test module of map php ward has made
core = 7.x
stylesheets[all][] = form.css
scripts [] = scripts/form.js
答案 0 :(得分:0)
1 /你不必“回应”任何东西。改为使用“返回”
2 /您不需要所有“&lt; head&gt; ...&lt; / head&gt;”部分已有一个模板(html.tpl.php)为您处理该部分(主题为:https://drupal.org/theme-guide/6-7)
3 /您应该使用表单API(https://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7)而不是使用原始表单
要回答原始问题,请参阅以下链接,说明如何添加CSS:http://adaptivethemes.com/how-to-add-css-files-in-drupal-7
答案 1 :(得分:0)
你可以在say_kartta()函数中使用drupal_add_css函数 https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_add_css/7