Создание HTML-компонента

В каталоге компонентов Oracle Content Management можно создать новый локальный компонент, а затем построить HTML-компонент, добавив и изменив файлы в папке активов.

Чтобы создать и построить HTML-компонент, выполните указанные ниже действия.
  1. Создайте компонент и назовите его HTML Component.
  2. Добавьте файл mustache.min.js в папку assets в HTML-компоненте.
  3. В папке assets создайте новый файл render.html с HTML-кодом для тела компонента. В этом примере создается файл render.html со следующим контентом:
    <ul class="wrapper">
        <li class="box">
         <h1 class="title">One</h1>
       <p class="text"> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
        </li>
        <li class="box"> 
         <h1 class="title">Two</h1>
         <p class="text"> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
        </li>
      <li class="box"> 
         <h1 class="title">Three</h1>
         <p class="text">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua./p> 
        </li>
      <li class="box">
         <h1 class="title">Four</h1> 
         <p class="text">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
        </li>
    </ul>
  4. В папке assets создайте новый файл design.css с таблицами CSS для компонента. В этом примере добавьте в файл design.css следующие строки:
    .wrapper {
      text-align: center;
    }
    .box {
      display: inline-block;
      position: relative;
      width: 200px;
      height: 200px;
      padding:0px 10px 10px 10px;
      background: transparent;
      border-width:1px;
      border-style:solid;
      border-radius: 5px;
      border-color:#CCCCCC;
      z-index: 0;
      margin: 2px 2px 2px 2px;
      transition: all .15s ease-in-out;
    }
    .box:hover {
      background: #9CC;
      z-index: 100;
      transform: scale(1.2,1.2);
      box-shadow: 0 5px 10px 0 rgba(0,0,0,.2);
    }
    .title {
       color:red;
    }
    .text {
       color:#555555;
    }
  5. Откройте файл render.js в папке assets и измените его содержимое на примененное ниже. Независимо HTML-кода и таблиц CSS, использованных в предыдущих действиях, следующий файл render.js преобразует HTML-код и таблицы CSS в страницу:
    /* globals define */
    define(['jquery', './mustache.min', 'text!./render.html', 'css!./design.css'], function($, Mustache, template, css) {
      'use strict';
    
      // ----------------------------------------------
      // Create a Mustache-based component implemention
      // ----------------------------------------------
      var SampleComponentImpl = function(args) {
        this.SitesSDK = args.SitesSDK;
    
        // Initialze the custom component
        this.createTemplate(args);
        this.setupCallbacks();
      };
      // create the template based on the initial values
      SampleComponentImpl.prototype.createTemplate = function(args) {
        // create a unique ID for the div to add, this will be passed to the callback
        this.contentId = args.id + '_content_' + args.viewMode;
        // create a hidden custom component template that can be added to the DOM 
        this.template = '<div id="' + this.contentid + '">' +
          template +
          '</div>';
      };
      SampleComponentImpl.prototype.updateSettings = function(settings) {
        if (settings.property === 'customSettingsData') {
            this.update(settings.value);
        }
      };
      SampleComponentImpl.prototype.update = function(data) {
        this.data = data;
        this.container.html(Mustache.to_html(this.template, this.data));
      };
      //
      // SDK Callbacks
      // setup the callbacks expected by the SDK API
      //
      SampleComponentImpl.prototype.setupCallbacks = function() {
        //
        // callback - render: add the component into the page
        //
        this.render = $.proxy(function(container) {
           this.container = $(container);
           this.SitesSDK.getProperty('customSettingsData', $.proxy(this.update, this));
        }, this);
        //
        // callback - SETTINGS_UPDATED: retrive new custom data and re-render the component
        //
        this.SitesSDK.subscribe(this.SitesSDK.MESSAGE_TYPES.SETTINGS_UPDATED, $.proxy(this.updateSettings, this));
        //
        // callback - dispose: cleanup after component when it is removed from the page
        //
        this.dispose = $.proxy(function() {
           // nothing required
        }, this);
      };
      // ----------------------------------------------
      // Create the factory object for your component
      // ----------------------------------------------
      var sampleComponentFactory = {
        createComponent: function(args, callback) {
          // return a new instance of the component
          return callback(new SampleComponentImpl(args));
        }
      };
      return sampleComponentFactory;
    });

Чтобы убедиться в построении HTML-компонента (контрольная точка 1), выполните указанные ниже действия.

  1. Убедитесь, что в папке assets в компоненте содержатся следующие пять файлов:

    • design.css
    • mustache.min.js
    • render.html
    • render.js
    • settings.html
  2. Добавьте новый HTML-компонент на страницу своего тестового сайта. В редакторе в режимах редактирования и предварительного просмотра компонент должен отображаться на странице следующим образом:

    Режим редактирования


    Описание GUID-17434B91-A25C-46EA-98D6-1A82CDA2D260-default.png ниже
    Описание иллюстрации GUID-17434B91-A25C-46EA-98D6-1A82CDA2D260-default.png

    Режим предварительного просмотра


    Описание GUID-DF2B9038-2774-49AC-A92F-A893F59D5D63-default.png ниже
    Описание иллюстрации GUID-DF2B9038-2774-49AC-A92F-A893F59D5D63-default.png