您好,我有一个需要编辑的 ASP 脚本.实际上我需要重新设置它发送的电子邮件的样式,所以我需要从中编辑 HTML.
Hello I have an ASP script that I need to edit. Actually I need to restyle the email that it sends, so I need to edit the HTML from it.
问题是html(来自asp文件)在每一行都有
The problem is the html (from the asp file) has on every row
HTML = HTML & ="
在其中(加上其他一些更改).我需要从该 ASP 中获取 HTML 代码,去掉开头的 html = html
部分,编辑双 ""
并将它们转换为单个 "
(我需要一一做,因为变量中也有引号).
in it (plus some other changes). I need to take the HTML code from that ASP, get rid of the beginning html = html
part, edit the double ""
and convert them to a single "
(I need to do that one by one, because the variables also have quotes in them).
然后,我用 HTML 重新设置页面的样式,然后我需要将它转换回来,以便我可以将它集成到 ASP (基本上再次引入双 '"' 和其他东西).
Than, I restyle the page with HTML and after that I need to convert it back so I can integrate it in ASP (basically introduce the double '"' again and stuff).
是的,我可以直接从 ASP 编辑 HTML,但我不知道它的外观,因为我无法运行脚本 (它需要来自服务器的其他文件,我不需要't 有权访问).
Yeah, I could edit the HTML from the ASP directly, but I don't know how it might look, because I can't run the script (it needs other files from the server, which I don't have access to).
问题:
有更好的方法吗?
某种方式可以直接预览我在 ASP 中所做的事情.或者也许是一个工具,可以让我从 ASP HTML 移动到 HTML 并更快地返回.
Some way of previewing what I'm doing in ASP directly. Or maybe a tool that let's me move from ASP HTML to HTML and back faster.
我当然知道我现在做的很蠢,所以一定有更好的办法.
I sure know that what I'm doing right now is quite dumb, so there must be a better way.
作为 @steve-holland 提及创建模板是避免代码中所有烦人的 HTML 字符串并使更改布局变得轻而易举的好方法.
As @steve-holland mentions creating a template is a great way to avoid all the annoying HTML strings in the code and makes changing layouts a breeze.
我过去曾自己处理过 HTML 模板脚本,通常我会构建一个 Scripting.Dictionary
,其中包含我将在模板中替换的键值对.
I've worked on HTML templating scripts myself in the past, usually I build a Scripting.Dictionary
that contains the key value pairs I will be replacing inside the template.
Function getHTMLTemplate(url, params)
Dim stream, keys, html, idx
Set stream = Server.CreateObject("ADODB.Stream")
With stream
.Type = adTypeText
.Charset = "utf-8"
Call .Open()
Call .LoadFromFile(url)
html = .ReadText(adReadAll)
Call .Close()
End With
Set stream = Nothing
keys = o_params.Keys
For idx = 0 To UBound(keys, 1)
html = Replace(html, keys(idx), params.Item(keys(idx)))
Next
Set keys = Nothing
Set params = Nothing
getHTMLTemplate = html
End Function
用法:
Dim params, html
Set params = Server.CreateObject("Scripting.Dictionary")
With params
.Add("[html_title]", "Title Here")
.Add("[html_logo]", "/images/logo.gif")
'... and so on
End With
html = getHTMLTemplate(Server.MapPath("/templates/main.htm"), params)
Call Response.Write(html)
示例main.htm
结构:
<!doctype html>
<html>
<head>
<title>[html_title]</title>
<link rel="stylesheet" type="text/css" href="/styles/main.css" />
</head>
<body>
<div class="header">
<img src="[html_logo]" alt="Company Name" />
</div>
</body>
</html>
为什么使用 ADODB.Stream
而不是 Scripting.FileSystemObject
?;
Why use a ADODB.Stream
instead of the Scripting.FileSystemObject
?;
您可以控制返回的 Charset
,如果需要,甚至可以从一个字符集转换为另一个字符集.
You can control the Charset
being returned and even convert from one to another if you need to.
如果模板特别大,您可以使用 Read()
方法以特定的缓冲区大小将内容流式传输,以提高读取的性能.
If the template is particular large, you can stream the content in using the Read()
method with a specific buffer size to improve the performance of the read.
这篇关于如何以更好的方式从 ASP 编辑 html?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!