Kentico:如何从搜索转换中访问搜索字符串?

时间:2017-03-29 05:33:01

标签: .net content-management-system kentico

如何从搜索转换中访问搜索字符串?无法在文档或论坛中找到它。试过<%#SearchedText()%>但当然不存在。

任何帮助将不胜感激。感谢。

1 个答案:

答案 0 :(得分:2)

搜索字符串通常在查询字符串中可用,因此您可以使用查询string macro,如

{%QueryString.name|(encode)%}
{%QueryString.name%}
{%HTMLEncode(QueryString.name)%}

其中查询字符串(可能)在你的情况下是'searchtext'。

如果您需要更复杂的搜索转换,您可以在公司网站上激励自己:

<div style="margin-bottom: 30px;">
<%-- Search result image --%>
    <div style="float: left; border: solid 1px #eeeeee; height:90px; width:90px; margin-right: 5px;text-align:center;">
       <img src="<%# GetSearchImageUrl("/CMSModules/CMS_SmartSearch/no_image.gif",90) %>" alt="" />
    </div>
    <div style="margin-left: 108px;">
        <%-- Search result title --%>
        <div>
            <a style="font-weight: bold" href='<%# SearchResultUrl(true) %>'>
                <%#SearchHighlight(HTMLHelper.HTMLEncode(CMS.Base.Web.UI.ControlsHelper.RemoveDynamicControls(DataHelper.GetNotEmpty(Eval("Title"), "/"))), "<span style='font-weight:bold;'>", "</span>")%>
            </a>
        </div>
        <%-- Search result content --%>
        <div style="margin-top: 5px; min-height:40px">
            <%#SearchHighlight(HTMLHelper.HTMLEncode(TextHelper.LimitLength(HttpUtility.HtmlDecode(HTMLHelper.StripTags(CMS.Base.Web.UI.ControlsHelper.RemoveDynamicControls(GetSearchedContent(DataHelper.GetNotEmpty(Eval("Content"), ""))), false, " ")), 280, "...")), "<span style='background-color: #FEFF8F'>", "</span>")%><br />
        </div>
        <%-- Relevance, URL, Creattion --%>
        <div style="margin-top: 5px;">
            <%-- Relevance --%>
            <div title="Relevance: <%# Convert.ToInt32(ValidationHelper.GetDouble(Eval("Score"), 0) * 100) %>%"
                style="width: 50px; border: solid 1px #aaaaaa; margin-top: 7px; margin-right: 6px;
                float: left; color: #0000ff; font-size: 2pt; line-height: 4px; height: 4px;">
                <div style="<%# "background-color:#a7d3a7;width:" + Convert.ToString(Convert.ToInt32(ValidationHelper.GetDouble(Eval("Score"), 0) * 50)) + "px;height:4px;line-height: 4px;"%>">
                </div>
            </div>
            <%-- URL --%>
            <span style="color: #008000">
                <%# TextHelper.BreakLine(SearchHighlight(SearchResultUrl(true),"<strong>","</strong>"),100,"<br />") %>
            </span>
            <%-- Creation --%>
            <span style="padding-left:5px;;color: #888888; font-size: 9pt">
                (<%# GetDateTimeString(ValidationHelper.GetDateTime(Eval("Created"), DateTimeHelper.ZERO_TIME), true) %>)
            </span>
        </div>
    </div>
    <div style="clear: both">
    </div>
</div>