我正在制作几个始终遵循已定义模板的 HTML 弹出窗口。
由于有一个模板(标题、内容、示例表、更多按钮),我想我可以通过将数据传递给包装函数来节省大量重复出现的 html,如下所示:
$device_popup_data = array(
'header' => 'Header text',
'content' => 'some text<span style ="bold"> Some more text</span>',
'example' => '<table><tbody><tr><td> A lot of text here, multi lined and messy',
'more' => '',
);
echo theme_uxt_expanded_popup($device_popup_data);
function theme_uxt_expanded_popup($data){
$head = isset($data['head'])?$data['head']:'';
$content = isset($data['content'])?$data['content']:'';
$example = isset($data['example'])?$data['example']:'';
$more_html = isset($data['more'])?$data['more']:'';
$output= '<div class = "expandedTooltip">';
$output.= '<h1>'.$head.'</h1>';
$output.= '<p>'.$content.'</p>';
if(!empty($more)){
$output.= '<a class = "popupShowMore"><p>'.$more.'</p></a>';
}
$output .= '</div>';
return $output;
}
这似乎是个好主意,直到我看到其中一些字段(如example
字段)可能包含大约 100 行 HTML。
将这些长字符串推送到示例变量中似乎会产生非常不可读的代码。像这样的东西:
$device_popup_data = array(
'header' => 'Header text',
'content' => 'some text<span style ="bold"> Some more text</span>',
'example' => '<table><tbody><tr><td> A lot of text here</td>,<td> multi lined and
messy, and if any one</td>
<td>wants to change this string it will be very hard</td>
Real string is much longer ... </table>',
'more' => '',
);
您知道执行此类操作的有效且易读的方法吗?