Tuning AIM

Release 1.0 - ...

Since AIM is a crucial player in Smartsite, it is crucial that Site Builders have more than basic understanding of what AIM does and how it can be configured optimally so that it can fulfill its important tasks.

As we've seen before, AIM scanning in fact is just another rendering on the AIM channel, and when an item is rendered on the AIM channel, one or more sub-renderings of that item take place using the references macro, which is in fact an embed with the Request Command hid=AIM. when a request is done like this, AIM-aware macros and Viper methods pass their relations to the AIM root macro in the AIM rendertemplate.

AIM is not a black box. You can see what aim gets out of your SXML yourself using a simple viper method:

Smartsite SXML CopyCode image Copy Code
<se:sitemap save="refs=this.aim.relations()" />
Smartsite SXML CopyCode image Copy Code
<se:format inputdata="refs">
 <se:rowformat><li>{this.field(2)} to {this.field(1)}</li></se:rowformat>
 <se:resultformat><ul>{this.result()}</ul></se:resultformat>
</se:format>

You will see that this syntax produces a number of ItemToFolder (AIMIF) relations, one for each folder displayed.

Using the AIM parameter

The shared AIM parameter can be used to specify AIM handling of a macro.

  • Internal
    AIM aware macros only. Lets the macro add the relations using the macro's internal logic.
  • External
    Makes AIM scan the output of the macro and spider the links it produces just like raw HTML data. Adds hard links (unless SoftLink is also set - 1.2+). 
  • Autonomous
    Sets the item in which the macro or Viper method is declared as the source for the AIM registration.
  • SoftLink (1.2+)
    Makes AIM genate soft links (Use only in combination with External)
  • InternalAutonomous
    Combines Internal and Autonomous
  • ExternalAutonomous
    Combines External and Autonomous
  • ExternalSoftLink (1.2+)
    Combines External and SoftLink
  • ExternalAutonomousSoftLink (1.2+)
    Combines External, Autonomous and SoftLink
  • Off
    Suppress any relation scanning for the macro

Conditional statements

When an item is rendered in AIM mode, some logic might be skipped due to conditions such as switch or if macros, condition parameters. This is due to the fact that AIM does not follow links and AIM rendering is done using embedding without any session or user context.

Consider the following block of SXML:

Smartsite SXML CopyCode image Copy Code
<se:switch expression="request.form(show)">
   <se:case value="sitemap">
      <se:sitemap />
   </se:case>
   <se:case value="parents">
       <se:parents />
   </se:case>
   <se:case>
       <se:xlinks />
   </se:case>
</se:switch>

The AIM rendering does not have any form post data, so only the fall-through case will be touched.

There is however an easy way to make sure AIM 'touches' conditional statements it would normally skip: the aim.addrequest() Viper method. Using this method, you can add add scenarios to the AIM rendering.

Smartsite SXML CopyCode image Copy Code
<se:switch expression="request.form(show)">
   <se:case value="sitemap">
      <se:sitemap />
   </se:case>
   <se:case value="parents">
      <se:parents />
   </se:case>
   <se:case expression="request.query('as')==1">
      <se:sitemap />
      <se:parents />
      <se:xlinks />
   </se:case>
   <se:case>
      <se:xlinks />
   </se:case>
</se:switch>
{aim.addrequest('as',1)}

TIP: avoid repeating blocks of code. If the code above would involve a lot of macro parameters, it would be better to redefine the code in translations or pagetranslations, and call those from the case logic sections.

Manually adding AIM relations

You can add any AIM relation yourself if desired. For example, the following code will not be able to derive the relations used and will revert to softlinks of all outgoing links:

Smartsite SXML CopyCode image Copy Code
<se:sqlquery 
 sql="select nr,title, author from {channel.view()} where parent in (2, 198) and author = ?"
 save="data"
 resulttype="datatable"
 params="{user.fullname()}"
/>
<se:xlinks inputdata="data" rowformat="{this.field(author)}" />

This will produce a number of ItemToItem, SoftLink (AIMS) relations. This is because the XLinks macro with an inputdata datatable will not able to determine its AIM folder relations.

In this case however, we can tell AIM what to do, using the AIM.References.Add() Viper method:

Smartsite SXML CopyCode image Copy Code
<se:sqlquery 
 sql="select nr,title, author from {channel.view()} where parent in (2, 198) and author = ?"
 save="data"
 resulttype="datatable"
 params="{user.fullname()}"
/>
<se:xlinks inputdata="data" rowformat="{this.field(author)}" aim="off"/> 
{aim.references.add(2, ItemToFolder)}
{aim.references.add(198, ItemToFolder)}

Now, we have informed AIM that we actually have AIMIF relations with two folders, 2 and 198, which is what we want.

The cache macro

In the case mentioned above, AIM tuning might not seem to be very important at first sight, but this changes as soon as we enclose it in a cache macro, since this macro relies on the AIM relations exposed by the contained SXML for its cache state management.