2016-01-13 54 views
0

我正在看sitecore中的參數模板,以瞭解頁面上的渲染項目。Sitecore參數模板 - 無法訪問圖像字段

我希望編輯器能夠多次添加渲染到頁面,但他們可以爲每個渲染定義不同的屬性,以便製作可重用的項目。

我已經定義字段:

標題 - 文本框 顏色 - 文本框 圖標 - 文本框 圖片 - 置頂的ImageField - 複選框

使用代碼如下所示,我能夠檢索文本字段元素但沒有爲圖像類型返回任何內容;我的意圖是也有圖標作爲一個下拉預置的產品清單,我有一種感覺,這個問題可能適用於也...

感謝您的任何援助

public partial class jonstest : System.Web.UI.UserControl 
{ 
    private NameValueCollection parameters; 
    public virtual NameValueCollection Parameters 
    { 
     get 
     { 
      if (this.parameters == null) 
      { 
       var parameters = this.Attributes["sc_parameters"]; 
       this.parameters = string.IsNullOrEmpty(parameters) 
             ? new NameValueCollection() 
             : Sitecore.Web.WebUtil.ParseUrlParameters(parameters); 
      } 
      return this.parameters; 
     } 
    } 


    protected void Page_Load(object sender, EventArgs e) 
    { 
     string rawParameters = Attributes["sc_parameters"]; 
     var parameters = Sitecore.Web.WebUtil.ParseUrlParameters(rawParameters); 
     var title = parameters["Title"]; 
     var colour = "tile-" + parameters["Colour"]; 
     var icon = "fa-" + parameters["Icon"]; 
     //var image = parameters["Image"]; 

     var image = this.Rendering.Parameters["Image"]; 



     TitleText.Text = title; 
     ColourValue.Attributes["class"] += " " + colour.ToLower(); 
     IconValue.Attributes["class"] += " " + icon.ToLower(); 

     foreach (string key in this.Parameters.Keys) 
     { 
      Image.Text += "Key=" + key + ";Value=" + this.Parameters[key] + ", "; 
     } 
    } 
} 
+2

請不要爲此使用渲染參數,而應將數據源用於渲染。每個人都可以擁有自己的數據源,然後允許測試,個性化和翻譯等。這些都不可能使用渲染參數。 – jammykam

回答

0

由於Jammykam指出請不要使用這類信息的渲染參數。這應當被存儲的數據源在哪裏可以正確存儲和語言版本等

但是如果你覺得地獄一心想做這種方式,那麼請看到這個以前的答案Sitecore - Image field in parameter template

只要記住,渲染參數實際上是作爲url編碼字符串提供的簡單鍵值對。這對傳遞複雜數據並不理想。

Cheers,Bo