In Fatwire, there are two asset types which contain code: CSElement and Template. From what I've found, Template is a combination of a CSElement and a SiteEntry. Currently, I use Templates as a wrapper for a set of CSElements, but I'm not totally sure this is the best way to structure my sites.

Is there any rule of thumb as to when a Template or CSElement is preferable over the other>? Or does it not really matter?

有帮助吗?

解决方案

The conversion is to use minimum logic part in templates and all cs elements should be called from the template. The logic should be coded in CSElements.

For example, if a page is rendered using one template. The navigation part will be done using one CSElement, Header logic will be in one template , logic to load body will be in another CSElement. all these CSelements will be called from the template. In short all these pagelets are rendered using CSElemtents. But it is called from Template.

The only plus point in template is that you can associate template with any asset. In all other cases CSElements are used.

其他提示

A modular strategy is strongly preferred when designing your pages. Templates can be typed or typeless.With typed templates, you could write the rendering logic per asset type/sub type thereby containing the data & presentation logic within the asset type boundary. Coding this way has multiple benefits as given below

  1. Helps you design your caching model. You can cache the templates as pagelets with different cache expiry settings.
  2. Dictates how the assets are wired to each other so that modifying the asset data or logic is contained within the pagelet.
  3. Templates can be swapped at an asset level using the template picker to produce a combination of different layouts.

A typeless template is not always preferred as it does not clearly define what asset it is trying to render or what sets of assets it is dependent on. So, a page rendered through typeless template may not live longer in the cache.

On the other hand, a CSElement is used to write common business logic and re-used across templates.

According with the Fatwire developer's guide a template is a containing page that lays out how the pagelets appear on the finished page and contains any code that must be evaluated each time tha page is viewed. A pagelet is the generated output of one or more CSElement.

You should design your pages using a modular strategy. A web page is composed of a container (templates) and a set of pagelets. This approach simplifies caching strategy and allows you to reuse common elements like menus, breadcrumbs or navigation bars.

See from fatwire perspective @ a high level.

Template : Template is a place holder for rendering your assets you create either FLEX or BASIC assets but cs element is not for rendering your assets even you create a site entry.

CS Element: CS element is something useful for doing some business logic. business logic has many forms.

CS element can be used for building the reusable components like Header , Footers that is common through out the page and this is called in templates.

In customizing fatwire Advance UI. say you can build your own tree tabs by writing a cs element and creating a site entry and this tree tab which is a custom section when ever it is loaded the site entry will be invoked.(this is complex but this is based on business requirement and this kind of situation we use cs element)

so Templates is for rendering assets and cs element is for doing some business logic.

template is cache-able where in cs element is not but if you still want to make it cache-able we can add a site entry to cs element

Template is selectable on an asset and is also tightly integrated with InSite editing and Timebox previewing. CSElement is not. These two are created for different purposes and cannot be compared.

I am assuming you are familiar with the concepts of Element Catalog and Site Catalog entries.

A CSElement is an asset which wraps an Element Catalog entry. An element may only be invoked internally, which is why it is the best place to write business logic. Typically caching is not relevant for such logic.

A SiteEntry is an asset which wraps a Site Catalog Entry. A Site catalog entry relates the "pagename" parameter is any standard ContentServer URL with the root element. This is the way in which an element may be exposed externally.

A Template is an asset which wraps an Element Catalog entry and multiple Site Catalog entries. A Template is a way of providing the rendering logic in an element in the context of different sites (which is provided by the site catalog entry). Templates also allow caching.

Having said the above, templates may be the best candidates for creating the "View", whereas elements may be the best candidates for the "Model" and other re-usables modules.

I would like to add a few points more.

  1. Calling CSElement from Template, CSElement is cached according to the calling template. So if you want different caching for CSElement from the calling Template, we need to have SiteEntry for that CSElement and you can define its caching.

  2. As described in guide, Template is used to render assets and SiteEntry+CSElement can be used for anything. For eg: Suppose you want to create a utility to search assets of particular type in CSElement and output is as JSON object. We can create SiteEntry asset for that CSElement with whatever name we want and call that site entry asset via URL like http://www.example.com/cs/ContentServer?pagename=SiteEntryName or can be called in JS file via ajax call where URL would be /cs/ContentServer?pagename=SiteEntryName. We can even pass parameters in the URL itself and handle them in CSElement. While making SiteEntry, select Wrapper as True, if you want to call via URL. Templates cannot be called via URL though, they require assets.

I hope this helps.

CSElement
A CSElement asset is used to write some piece of code which is reusable. It is rendered by a template. A CSElement asset is an element and doesn’t have site entry.

They do not have cache criteria. We need to use SiteEntry to cache the output of CSElement.

An entry will be created in CSElement database table as a row when a CSElement is created.

render:callelement tag is used to call the CSElement assets.

Site Entry
Site entry assets are page names. When your code calls an element directly by element name without going through the page name, the output of the called page is cached as part of that page. 
If you want to cache the output of the CSElement and to maintain its own cache criteria, your code should call the CSElement through a specific page name. To achieve this you need to create a SiteEntry and map it to the CSElement.

An entry will be created in the SiteEntry database table as a row when a SiteEntry is created.

Template


A Template asset is both an element and a page or pagelet that renders an asset. It mean to create to maintain consistent look & feel for a website. A Template could be a complete page or a part of the page. So this way any number of templates we can create.

These are chacheable. They have cache criteria set for them that determines whether they are cached and for how long?
 We use render:calltemplate tag to call the Template assets.

An entry will be created in the Template database table as a row when a Template is created.

Bharath
http://devble.com/what-are-cselement-siteentry-and-template-assets

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top