GithubHelp home page GithubHelp logo

jormenes / aem-sightly-sample-todomvc Goto Github PK

View Code? Open in Web Editor NEW

This project forked from adobe-marketing-cloud/aem-htl-sample-todomvc

0.0 1.0 0.0 272 KB

AEM Sightly code example of a simple web application.

Home Page: http://docs.adobe.com/content/docs/en/aem/6-0/develop/sightly.html

License: Apache License 2.0

HTML 10.36% JavaScript 55.98% CSS 33.66%

aem-sightly-sample-todomvc's Introduction

Sightly TodoMVC Example

This example shows how to build components in AEM 6 with Sightly. It's a feature-complete implementation of the famous TodoMVC exercise, which is traditionally meant for client-side JavaScript frameworks. This implementation though shows how such an application can easily be built in AEM and it's status persisted on the server using the Apache Sling REST framework.

All in about 300 lines of server- and client-side JavaScript code, following the latest AEM best practice!

Learning Sightly

Sightly is the new HTML templating system, introduced with AEM 6.0. It takes the place of JSP (Java Server Pages) and ESP (ECMAScript Server Pages) as the preferred HTML templating system for AEM.

The Sightly Documentation on the AEM Site is a great resource for getting started.

You can also read following blog posts:

Get help from other Sightly users:

If you are interested to learn how we came up with Sightly, check out the Behind the Scenes Youtube channel.

Implementation

The server sets a number of data attributes to the HTML elements that are interactive. These data attributes are instructing the app front-end about the asynchronous POST requests that are to be done when interacting with these elements, in order to persist the manipulations to the server. After each manipulation, the app content is reloaded through an asynchronous query to retreive the HTML fragment of the view that must be updated.

Beyond the classic MVC, this architecture also has following particularities:

  • The Sling Post Servlet makes it possible that no code has to be written to handle the POST requests.
  • Through the data attributes set by the server, the client needs no knowledge of how to structure the data for the Sling Post Servlet.
  • To retreive the HTML fragment of what must be updated on the page, a simple todoapp selector allows to trigger the specific template that handles that part of the view.
  • The filters (to show all, or only active or completed items) use an additional selector, which allows the server to know which items to render.

Note that Java could also have been used instead of the server-side JavaScript files.

Content

The nodes located in the content repository at /content/todo are serialized in a .content.xml file with following content:

  • jcr:content The content node for the todo page. It contains the title and various labels that are to be displayed on the page, but important is the sling:resourceType property, which makes this node rendered by the page component.
    • todo_<N> The todo items with their titles and completed status. As the sling:resourceType property defines it, they are rendered by the item component.

Server-side components

AEM components render individual content nodes based on their sling:resourceType properties.

  • page Renders the page content node.
    • page.html Entry point: The outer page markup that doesn't change when actions are performed.
    • page.js Server-side script that prepares additional data model needed by page.html.
    • todoapp.html Renders the list of todo items. Called directly when fetching what changed in the view.
    • todoapp.js Server-side script that prepares additional data model needed by todoapp.html; also defines the data attributes that will instruct the front-end POST requests.
  • item Renders the todo item content nodes.
    • item.html Renders the markup for the items.
    • item.js Server-side script that prepares additional data model needed by item.html; also defines the data attributes that will instruct the front-end POST requests.
  • utils Collection of reusable scripts.
    • filters.js Defines what filters are set depending on the request selectors (i.e. to show all, or only active or completed items).

Client-side libraries

Client libraries can conveniently combine and minimize multiple CSS and JS files:

Running it

  • Create package
    • Get the code from this Git repository, for e.g. with following command line:
      git clone https://github.com/Adobe-Marketing-Cloud/aem-sample-sightly-todomvc.git
    • Create a ZIP file from the app folder, for e.g. in a Unix shell you can do:
      cd aem-sample-sightly-todomvc/app
      zip TodoMVC.zip -r jcr_root META-INF
  • Start AEM
    • Double-click on the AEM JAR to start an instance if you haven't done that already.
    • Once you're prompted with a login in your browser, enter admin as username and password.
  • Install package
    • Goto the AEM Package Manager.
    • Click on Upload package and browse for your ZIP file, then hit OK.
    • Once TodoMVC.zip shows up at the top of the list, click on Install => Install.
  • Run the app
    • Access the Todo page.

aem-sightly-sample-todomvc's People

Contributors

gabrielwalt avatar labertasch avatar raducotescu avatar

Watchers

Jorge M avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.