如何编辑从ASP的HTML以更好的方式? [英] How to edit the html from ASP in a better way?

查看:125
本文介绍了如何编辑从ASP的HTML以更好的方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我有一个ASP脚本,我需要编辑。其实我需要restyle其发送的电子邮件,所以我需要从它编辑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 & =" 

在它(加上一些其他的变化)。我需要的HTML code从ASP,摆脱了年初 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).

比,我restyle页面的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,但我不知道是怎么回事看起来,因为我不能运行脚本的(它需要一个从服务器,这我不其他文件吨有访问)

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).

问题:

是否有这样做的更好的办法?

Is there a better way of doing this?

$ P $的一些方法pviewing什么我直接做在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.

推荐答案

史蒂夫 - 荷兰 <一个HREF =htt​​p://stackoverflow.com/a/35994392/692942>提到创建模板是为了避免所有在code恼人的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的;


  1. 您可以控制​​在字符集被退回,如果需要,甚至从一个到另一个转换。

  1. You can control the Charset being returned and even convert from one to another if you need to.

如果模板是特别大,你可以流中使用阅读()方法与特定的缓冲区大小来提高读取性能的内容

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以更好的方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆