简体   繁体   English

使用AngularJS和Sitecore(SPA)构建单页应用程序

[英]Building a Single Page Application with AngularJS and Sitecore (SPA)

I want to implement Sitecore application (single page design with angular js) : 我想实现Sitecore应用程序(使用angular js进行单页设计):

  1. Is that possible ? 那可能吗 ?
  2. If it is possible, what about experience editor, it will work with it ? 如果可能的话,体验编辑器可以使用它吗?
  3. What about Sitecore personalization ? 那么Sitecore的个性化呢?
  4. I have no experience with angular js. 我没有使用angular js的经验。 what should I take in my consideration to achieve this 我应该考虑什么才能实现这一目标

I will use Sitecore 8. i found this helpful blog about that but as he mentioned, page editor simply won't work 我将使用Sitecore8。我发现这个有用的博客 ,但是正如他所说, 页面编辑器根本无法工作

Thanks. 谢谢。

1. 1。

Yes it is possible, I implemented a SPA in Sitecore 7 using AngularJS for the front-end and WebAPI to serve the data from Sitecore Items and it all worked really well together. 是的,是有可能的,我在Sitecore 7中实现了SPA,使用AngularJS作为前端,并使用WebAPI来提供Sitecore Items中的数据,并且它们都可以很好地协同工作。

You could look into using Sitecore MVC Controllers which will work just as well as WebAPI. 您可以考虑使用Sitecore MVC Controllers ,该Controllers与WebAPI一样好。 Or if you have time to learn a new Sitecore Technology you can look into using Sitecore's Entity Service . 或者,如果您有时间学习新的Sitecore技术,则可以使用Sitecore的Entity Service进行调查 Either will work for serving data from Sitecore. 两者都可以从Sitecore提供数据。

From experience I recommend you make controllers which are responsible for a single type of data consumed by the AnglarJS. 根据经验,我建议您将控制器设计为负责AnglarJS消耗的单一数据类型。 The models passed by the controllers should be lean, containing only data relevant to the controllers purpose. 控制器传递的模型应精简,仅包含与控制器用途相关的数据。

2. 2。

For my implementation, the Experience Editor would not work as I used AngularJS to manipulate and present the data. 对于我的实现,由于我使用AngularJS来处理和呈现数据,因此体验编辑器无法正常工作。 It could be possible to use Sitecore Controls if you don't pull out the data using AngularJS but I don't think it'll be possible without hacking at it with code. 如果您不使用AngularJS提取数据,则可以使用Sitecore控件,但我认为如果不使用代码对其进行破解,这是不可能的。

3. 3。

Personalisation through the Experience Editor should be possible if you use Sitecore Controls. 如果您使用Sitecore控件,则应该可以通过“体验编辑器”进行个性化设置。 Personalisation through the Content Editor and code will be possible. 通过内容编辑器和代码的个性化将成为可能。 I recommend you build your SPA as you would most Sitecore implementations; 我建议您像大多数Sitecore实施一样构建SPA。 Layout, Sublayout etc. You can implement personalisation through code in the Controllers, Application Logic etc 布局,子布局等。您可以通过控制器,应用程序逻辑等中的代码来实现个性化

4. 4。

I had no experience with AngularJs either but I learned everything I needed to know from tutorials and the rest is logical enough for you to figure out if you're familiar with any programming language. 我也没有使用AngularJs的经验,但是我从教程中学到了我需要知道的所有内容,其余的内容合乎逻辑,可以让您弄清楚您是否熟悉任何编程语言。 I recommend you work through this Codecademy Tutorial that has you completing exercises - its how I learned. 我建议您通过本Codecademy教程来完成练习,这是我的学习方法。

I've yet to write a blog on how I achieved it but Dave Peterson has written two blogs on his experiences with SPA with Sitecore and AngularJs that might be worth a read. 我还没有写一篇关于如何实现它的博客,但是Dave Peterson撰写了两个博客,介绍了他在Sitecore和AngularJs上的SPA经验,值得一读。

  1. Yes it is possible 对的,这是可能的
  2. Yes you can use the experience editor, BUT you have to build the site in a specific way. 是的,您可以使用体验编辑器,但是您必须以特定的方式构建站点。 Not in the "normal" way. 不以“正常”方式。
  3. Again, same as experience editor, you can use it, but the site has to be built to accommodate that. 再次,与体验编辑器相同,您可以使用它,但是必须构建该站点来适应该需求。
  4. Not sure on Angular - I have used backbone, but the principles are very similar. 在Angular上不确定-我已经使用了骨干网,但是原理非常相似。

I have a blog post on how we achieved this for a client: http://www.sitecorenutsbolts.net/2015/12/07/Single-Page-Applications-in-Sitecore-Part-I/ 我有一篇关于如何为客户实现此目标的博客文章: http : //www.sitecorenutsbolts.net/2015/12/07/Single-Page-Applications-in-Sitecore-Part-I/

Have a read of that, it gives the principles you should follow to enable Sitecore in an SPA. 阅读有关内容,它提供了在SPA中启用Sitecore时应遵循的原则。

Anything is possible in Sitecore, but some customization are too complex to be considered practical. Sitecore可以做任何事情,但是某些自定义过于复杂,以至于不可行。

You can easily build SPA application with the following limitations: 您可以轻松构建具有以下限制的SPA应用程序:

  1. Display various views with either 使用任一显示各种视图

    a) server generated templates, or a)服务器生成的模板,或

    b) static .html template with Sitecore-managed content (retrieved as json via custom controllers or Content API) and bound to template using AngularJS. b)具有Sitecore托管内容的静态.html模板(通过自定义控制器或Content API检索为json),并使用AngularJS绑定到模板。

  2. Limit the scope of personalization to just content . 将个性化的范围限制为仅满足要求

  3. Have experience or page editor view significantly different from the end-user experience. 经验或页面编辑器视图与最终用户体验明显不同。 And even then, this will require separate design to create and maintain. 即使那样,这仍需要单独的设计来创建和维护。

What is significantly more challenging is: 更具挑战性的是:

  1. Utilize Personalization to dynamically display different renderings. 利用个性化来动态显示不同的渲染。 Hide/show renderings, etc. 隐藏/显示效果图等

  2. Have Experience Editor reflect the actual design of the SPA experience 让体验编辑器反映SPA体验的实际设计

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM