Sitecore学习总结(1)


			LinkField link = (LinkField)homeitem1.Fields["baidu"];
			
			string url = link.Url;

sitecore是一种CMS(内容管理系统,位于web前端和后端办公系统或流程之间的软件系统)

首先进行sitecore站点搭建(以7.2版本为例)

1.创建本地服务器文件(一般是解压包包含data,database,website文件夹)

 2.将database中的数据库附加到本地数据库

3.修改webconfig定位到license文件(license差不多是一个非常贵的使用sitecore的通行证)

 4.修改appconfig文件夹中的connetionstring

 

 Source=.代表链接本地数据库,值得一提的是core,master,web库的区别为Core Database是Sitecore应用程序的主干,它可用于多种用途。Master数据库是Sitecore中的主数据库也称为内容创作数据库。无论何时创建新内容,它都将存储在主数据库中。Web数据库包含网站的实时内容,也称为已发布的数据库。

具体的区别链接:Sitecore中Core,Master和Web数据库之间的区别 - JackYang - 博客园 (cnblogs.com)

5.在iis上发布,程序池配4.0,定位到website文件夹。

6.配置hosts文件,将本地部署进去

7.配置成功。

Sitecore搭建开发环境

1.在vs中创建空的c#web项目

2.将服务器中website文件夹具体内容复制到web项目中

3.在vs中点开显示所有文件,包含到项目里,并将项目中bin文件夹复制会服务器bin文件夹中,保证开发环境和服务器站点环境一致。

4.配置项目生成事件(右击项目-属性-生成事件)使其生成同步改变到服务器文件夹。

宏命令:更改目标文件夹复制到生成事件中

xcopy "$(TargetPath)"          "D:\sitecore72demo1\Website\bin\*.dll"  /R/E/Y
xcopy "$(ProjectDir)*.aspx"  "D:\sitecore72demo1\Website\*.aspx" /E/Y
xcopy "$(ProjectDir)*.ascx"  "D:\sitecore72demo1\Website\*.ascx" /R/E/Y
xcopy "$(ProjectDir)*.ashx"  "D:\sitecore72demo1\Website\*.ashx" /R/E/Y
xcopy "$(ProjectDir)*.asax"  "D:\sitecore72demo1\Website\*.asax" /R/E/Y
xcopy "$(ProjectDir)*.xslt"   "D:\sitecore72demo1\Website\*.xslt" /E/Y
xcopy "$(ProjectDir)*.css"    "D:\sitecore72demo1\Website\*.css" /E/Y
xcopy "$(ProjectDir)*.swf"   "D:\sitecore72demo1\Website\*.swf" /E/Y
xcopy "$(ProjectDir)*.jpg"    "D:\sitecore72demo1\Website\*.jpg" /E/Y
xcopy "$(ProjectDir)*.gif"     "D:\sitecore72demo1\Website\*.gif" /E/Y
xcopy "$(ProjectDir)*.js"    "D:\sitecore72demo1\Website\*.js" /E/Y
xcopy "$(ProjectDir)*.png"     "D:\sitecore72demo1\Website\*.png" /E/Y
xcopy "$(ProjectDir)*.html"     "D:\sitecore72demo1\Website\*.html" /E/Y
xcopy "$(ProjectDir)*.xml"     "D:\sitecore72demo1\Website\*.xml" /E/Y
/E/Y
xcopy "$(ProjectDir)*.html"    
 "D:\sitecore72demo1\Website\*.html" 
/E/Y
xcopy "$(ProjectDir)*.xml"   
  "D:\sitecore72demo1\Website\*.xml" /E/Y

 开发环境搭建成功。vs中可加如sitecore rocks插件。

Sitecore的基本开发,

基本概念

1.content tree

2.Item

3.template

4.field

5.layout/sublayout

6.placeholder

先从sitecore运行机制说起

 下面搭建一个最简单的站点

1.首先在Templates-sample新建一个home和product templat模板页

添加新的数据类型

点击options添加standard values编写模板页默认值

 

 在content中添加home节点,在home节点加入product的insert options

 在home节点下创建三个product子节点。

 

 新建menu xslt rendering(主页导航),product display xslt rendering(产品显示),generic display sublayout(布局)

 menu.xslt

<xsl:variable name="home" select="sc:item('/sitecore/content/home',.)"/>
  
  <!-- mian -->
  <xsl:template match="*" mode="main">
    <br/>
    <sc:link select="$home">
      <xsl:value-of select="$home/@name"/>
    </sc:link>
    <br/>
    <xsl:for-each select="$home/item">
      <sc:link>
        <sc:text field="Title"/>
      </sc:link>
      <br/>
    </xsl:for-each>
  </xsl:template>

product display.xslt

<xsl:variable name="home" select="sc:item('/sitecore/content/home',.)"/>
  
  <!-- mian -->
  <xsl:template match="*" mode="main">
    <h1>
      <sc:text field="title"/>
    </h1>
    <sc:text field="description"/>
    <br/>Price:<b>
      <sc:text field="price"/>
    </b>
    
  </xsl:template>

在sitecore中 sublayouts下新建generic display

开发环境中添加代码

 

 generic display.ascx

<h1><<sc:FieldRenderer ID="MyTitle" runat="server"  FieldName="Title"/></h1>
<br />
<sc:FieldRenderer ID="MyDescription" runat="server" FieldName="Description" />

在layout-renderings下新建menu,product,绑定 menu.xslt和product display.xslt

 在layout-layouts下新建一个browser layout

 附加到开发环境

browser layout.aspx代码如下

<form method="post" runat="server" id="mainform">
      <div style="width:800px;"><i>Header</i></div>
      <div style="width:800px">
          <div style="float:left;width:200px;">
              <%--<sc:XslFile ID="Xslfile1" runat="server" Path="/xsl/Menu.xslt" />--%>
              <sc:Placeholder ID="Placeholder2" runat="server" Key="menu" />
          </div>
          <div style="float:left;width:600px;">
              <sc:Placeholder ID="Placeholder1" runat="server" Key="content" />
          </div>
      </div>
      <div style="clear:both"></div>
      <div style="width:800px;"><i>Footer</i></div>
  </form>

在home中通过presentation-details绑定布局和控件,注意key值

 

然后save,publish。就搭建好一个简单的站点。

下面总结开发步骤

1.先规划content tree结构

2.页面切分

3.Template设计

4.建立content tree

  • content
  • layout
  • media library
  • template

 5.数据绑定

  • Template字段数据类型
<sc:FieldRenderer ID="MyTitle" runat="server"  FieldName="Title"/>
    <sc:Text ID="MyTitle2" runat="server"  FieldName="Title"/>
  • sitecore控件
  1. sc:placeholder(重要属性key)
  2. sc:link(重要属性field)
  3. sc:text
  4. sc:image
  5. sc:date
  6. sc:editframe
  • 如何绑定:Item field名称和sitecore 控件的field属性内容相同,就能实现绑定
  • 支持pageeditor下进行内容修改(editframe)

6.sitecore API

  • 获取指定节点
  1. sitecore.context.item获取当前url对应的item(using sitecore及sitecore.data.item)
Item homeitem1 = Sitecore.Context.Item;

    2.sitecore.data.database.getitem()获取 

Item homeitem2 = Sitecore.Context.Database.GetItem(new Sitecore.Data.ID("{165BC530-BD6B-404F-9497-D074DD0AB23C}"));
  • 获取节点数据,field
    string title = homeitem1.Fields["Title"].Value;
    			string title2 = homeitem1["Title"];//纯文本

     获取linkfield(using sitecore.data.fields)

LinkField link = (LinkField)homeitem1.Fields["baidu"];
string url = link.Url;
  • 查找节点
  1. query(Developercenter-xpathbuilder)
  2. fast query
  3. lucene(开源工具)
  • 遍历并绑定(使用asp:repeater)

7.stiecore调试:通过附加进程的方式调试

8.多语言开发

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值