2013-08-01 36 views
1

我試圖在ektron中調用google-jquery和一些內聯腳本/樣式標記。我是CMS的新手,這甚至有可能嗎?代碼如下:Ektron中的內聯腳本標記/ JQuery

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script> 
<script type="text/javascript"> 
    $(document).ready(function(){ 

     $('#accordion-js').find('h2').click(function(){ 
      $(this).next().slideToggle(); 
      }).next().hide(); 
     }); 

</script> 
<script type="text/javascript"> 
$(document).ready(function(){ 

$('#accordion-js').find('h2').toggle(function(){ 
    $(this).css("background-color","#04396D"); 
    $(this).css("background-image","url('101_up.png')"); 
    $(this).css("background-position", "center right"); 
    $(this).css("background-repeat","no-repeat"); 
    $(this).css("color","#FFF"); 
    }, 
function(){  
    $(this).css("background-color","#f4f4f4"); 
    $(this).css("background-image","url('101_down.png')"); 
    $(this).css("background-position", "center right"); 
    $(this).css("background-repeat","no-repeat"); 
    $(this).css("color","#777"); 
    }); 
}); 
</script> 
+0

我對你正在嘗試做的有點不清楚。它看起來像你已經成功包括jQuery並正在使用它。 是你的問題如何使用上面的代碼在Ektron中創建切換手風琴? 要使用上面的代碼,只需將其放置在您的ASPX模板中,它將像任何webforms應用程序一樣運行。 – MaxPRafferty

回答

0

有幾種方法可以做到這一點。

如果你是從後面的代碼做到這一點。下面的警告框可以儘可能多的代碼,只要你喜歡。

JS.RegisterJSBlock(this, "alert('hello');", "MyAlertId"); 

JS.RegisterJSInclude(this, "http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js", "GoogleJQuery1.7."); 

Ektron默認包含它自己的jQuery,可能值得一試。

一個創可貼的解決方案是使用HTML內容塊並粘貼代碼並使用內容塊控件插件將其放到頁面上。不是最好的方式,但它今天完成了這項工作,但沒有人會讚揚你的恆星解決方案。

我們做了什麼來解決這個問題是構建一個Widget,它使用代碼隱藏技術將代碼放入頁面。它使用自定義的智能表單並適用於這些緊急情況。

祝你好運。

1

如果您嘗試從CMS內容生成手風琴,則需要執行一些額外步驟才能將內容檢索到您的頁面上。

步驟1:創建一個aspx頁面模板,並把該javascript代碼到它

步驟2:刪除重複的控制,如ASP:轉發到您的模板。有很多關於這方面的教程。一個簡單的例子是http://msdn.microsoft.com/en-us/library/zzx23804(v=vs.85).aspx

第3步:數據綁定ektron內容列表到你的中繼器。此代碼將類似於如下:

ASPX標記:

<div id="accordion-js"> 
    <asp:Repeater ID="myAccordion" runat="server"> 
    <ItemTemplate> 
     <h2>Content Title:<%# Eval("Title") %></h2> 
     <p>Content Body:<%# Eval("Html") %></p> 
    <ItemTemplate> 
    </asp:Repeater> 
</div> 

Aspx.cs代碼隱藏:

protected void Page_Load(object sender, EventArgs e) 
{ 
    //create a content manager to interact with the CMS 
    Ektron.Cms.Framework.Content.ContentManager cCRUD = 
    new Ektron.Cms.Framework.Content.ContentManager(); 
    //create a content criteria to select content meeting specified filtering criteria from the manager 
    Ektron.Cms.Content.ContentCriteria contentSelector = 
    new Ektron.Cms.Content.ContentCriteria(); 
    //specify a filter - in this case, all content in folder '0' (the root) 
    contentSelector.AddFilter(
    Ektron.Cms.Common.ContentProperty.FolderId, 
    Ektron.Cms.Common.CriteriaFilterOperator.EqualTo, 
    0); 
    //get the list and set it as the source of our repeater 
    myAccordion.DataSource = cCRUD.GetList(contentSelector); 
    //bind the list to the repeater 
    myAccordion.DataBind(); 
}