Translate

Showing posts with label associations. Show all posts
Showing posts with label associations. Show all posts

Saturday, July 6, 2013

Example 3: Rendering Associations

This example illustrates how to render ASSOCIATIONS - Named and Unnamed (Collections, Query and Asset associated)

GENERAL STEPS TO FOLLOW:
  1. Load the asset (using asset:load tag)
  2. Get the association (using asset:children tag)
  3. Fetch attributes (by looping through list using ics:listloop tag)
CASE 1: Retrieving named association (Consider a case where a query asset is associated with Page).

<asset:load name="HomePage" type="Page" field="name" value="Home" site='<%=ics.GetVar("site")%>'/>
<asset:children name="HomePage" list="LatestNewQuery" objectype="Query" code="LatestNews"/>
<ics:listloop listname="LatestNewQuery"> 
     <ics:listget listname="LatestNewQuery" fieldname="description"/>
</ics:listloop>

INFO:
  • The above code retrieves the query asset that has been associated with a page asset through the "LatestNews" association.
  • code="LatestNews" - This is required to retrieve NAMED association.
  • If asset is associated to another asset, use the above way. (for eg: list of images associated with article assets.)
CASE 2: Retrieving unnamed association (Collection asset consisting of asset type - Article):


<asset:load name="NewsCollection" type="Collection" objectid='<%=ics.GetVar("id")%>'/>
<asset:get name="NewsCollection" field="name"/><br/>
<asset:children name="NewsCollection" code="-" order="nrank" objecttype="Article" list="articleList"/>
<ics:listloop listname="articleList">
     <ics:listget listname="articleList" fieldname="description"/><br/>
</ics:listloop>

INFO:
  • The above code retrieves a collection of articles and then displays the description field of each article
  • Notice: for unnamed associations, we use "-" in code parameter (code="-") while using asset:children tag.
  • order="nrank" - This can be used to retrieve list sorted by rank started at number 1. Use "nrank desc" for descending order.
  • Above mentioned example assumes that your asset was loaded for further purpose to load siteplan or to scatter other values using asset:scatter. But if you only want to retrieve associated assets, don't use asset:load. You can directly load association by providing assetid and asset type info to <asset:children> tag (Check how in tag reference)

--------------------------------------------------------
SUGGESTIONS/COMMENTS ARE INVITED
--------------------------------------------------------