如果您不使用 Kentico,我想我找到了一个涉及制作 webPart 或控件的解决方案。
public static void AddScriptToHead(HtmlHead h, string script, bool AddScriptTags)
{
Literal l = new Literal();
if (AddScriptTags)
l.Text = "<script type=\"text/javascript\" src=\""
+ script +
"\"></script>";
else
l.Text = script;
h.Controls.Add(l);
}
protected void SetupControl()
{
if (this.StopProcessing)
{
// Do nothing
}
else
{
string theme = Page.Theme;
if (theme != null)
{
if (theme.Equals("Card"))
{
AddScriptToHead(Page.Header, "~/App_Themes/Cardamon/js/cufon-colors-classic.js", true);
AddScriptToHead(Page.Header, "~/App_Themes/Cardamon/js/Charis_SIL_700.font.js", true);
}
else if (theme.Equals("CardamonWave"))
{
AddScriptToHead(Page.Header, "~/App_Themes/Cardamon/js/cufon-colors-wave.js" ,true);
AddScriptToHead(Page.Header, "~/App_Themes/Cardamon/js/Lobster_14_400.font.js",true);
}
else if (theme.Equals("CardamonAncient"))
{
AddScriptToHead(Page.Header, "~/App_Themes/Cardamon/js/cufon-colors-ancient.js", true);
AddScriptToHead(Page.Header, "~/App_Themes/Cardamon/js/Charis_SIL_700.font.js", true);
}
else
{
//Y U no theme?
}
}
}
}
我想扩展它以在将来接受脚本和主题作为属性,但这现在可以工作。