Create a View to Render a Registered Page Type

When you register a page type with the PageType Component, you must also create a view to render the data when a user navigates to an instance of that page type. When creating this view, follow these best practices:

To set up a view to render a page type:

  1. Open the view file or create a new one. This file should be located in the extension’s JavaScript directory.

  2. Declare PageType.Base.View as a dependency and add it to the module definition function.

  3. Declare the view’s template file and add it to the module definition function.

    The following example adds My_New_Default_Template.tpl as a dependency:

  4. Declare any third-party libraries as needed.

    The following example declares MyPageType.View.js and My_New_Default_Template.tpl as dependencies:

                    define('MyPageType.View'
    ,   [
          'PageType.Base.View'
       ,   'My_New_Default_Template.tpl'
       ]
    ,   function (
          PageType
       ,   My_New_Default_Template_tpl
       )
    {
    //... 
    
                  
  5. Set up the view to extend PageType.Base.View.

                    define('MyPageType.View'
    ,   [
          'PageType.Base.View'
       ,   'My_New_Default_Template.tpl'
       ]
    ,   function (
          PageType
       ,   My_New_Default_Template_tpl
       )
    {
       'use strict';
    
       return PageType.PageTypeBaseView.extend({  
    //... 
    
                  
  6. Include the template that your associated page type is using as the default layout.

    This template is the same file declared when you register your page type in the extension’s entry point JavaScript file (registerPageType() method). See Register a Page Type for details.

                    define('MyPageType.View'
    ,   [
          'PageType.Base.View'
       ,   'My_New_Default_Template.tpl'
       ,   'jQuery'
       ]
    ,   function (
          PageType
       ,   My_New_Default_Template_tpl
       ,   jQuery
       )
    {
       'use strict';
    
       return PageType.PageTypeBaseView.extend({  
       
          template: My_New_Default_Template_tpl
    
       ,   initialize: function (options) {
       //... 
    
                  
  7. Complete the view file as necessary to meet your needs.

Related Topics

Register Page Types and Templates for SMT
Register a Page Type
Register a Template
Supported Page Types

General Notices