You are here: Home >> How-Tos >> How to insert an AQP with overrides using javascript

How-To: How to insert an AQP with overrides using javascript

By Lyle B Hojbjerg Clarke

To do this trick you will need a content only template. This is very easy to make. Create a new template, name it contentOnly, and make sure that the only code in the entire thing is the macro

<!--#pageContent--> 

Okay, here goes:

1. Create an AQP. You can name it anything you want.

2. Go to the 'Basic' tab and change the template to contentOnly and the MIME type to text/javascript. Change all the other drop down boxes to [none]. Save your changes.

3. Under the 'Query Options' tab make sure 'Allow search arg overrides' reads Yes. Everything else on this tab is up to you. Adjust it so that you get the results you want.

4. Edit the 'Query Defaults' tab as you please.

5. On the 'Form Settings' tab make sure 'Show Form' reads Yes.

6. Skip a tab now, and go to the 'Error Messages' tab (we'll leave the trickiest to last). Under the error message tab make sure that both templates are javascript safe. The easiest way to do this is like this:

document.write( "your text goes here" );

NOTE: It is very important that there are no carriage returns in either template, as carriage returns break javascript.

7. Now go to the 'Results Settings' tab. You can pretty much make this do whatever you want. It is important however to remember that every single line of code MUST start with document.write( " and end with " );

NOTE: Apart from the obligatory double quotes at the start and end of each line, you can not use any double quotes anywhere in your code. None at all. Use single quotes instead.

As an example of a very simple setup (it makes a list of message headings linking to their messages.

a. Make the 'Page Content Template' read:

<!--#queryResult--> 

b. Make the 'Query Result Template' read:

<!--#queryResultBody--> 

c. Make the 'Message Template' read:

<a href=<!--#msgURL-->><!--#MsgSubject--></a><br>  

NOTE: Conversant is a wonderful application, and very powerful. If you think about it long enough you can get Conversant to generate any page that you want in a javascript safe fashion. In another words, you don't have to stick to the simple example I am using above. For an example of something a little more complex, take a look at the right hand columns on any page at Mooloo.

8. You are now read to insert the query. You will be doing this in the appropriate page template. But for testing purposes, you can try the code out anywhere. Insert the code like this.

<script src="<!--#siteUrl-->AQP_PATH_&_NAME"></script>

9. Next is the really cool bit. Search overrides. Search overrides go directly onto the end of the AQP path and name. In fact, they actually are part of the AQP path and name. You simple add a question mark and then the overrides. For example:

<script src="<!--#siteUrl-->AQP_PATH_&_NAME?limit=5&endDate=<!--#msgCreationDate-->&sortKey=Date&sortDir=des"></script>

I've added some colour to split up the overrides a bit. The first one limits the AQP so that it only returns 5 results. The second one tells the AQP that the end date of the search is to be the date the message being displayed was created. The third one tells the AQP to sort the results in order of date, and the fourth one says that sort direction should be descending (newest first). Each new override has to start with an '&' (shown in green in the example above).

The above however is only an example. There are heaps and heaps of search overrides, I don't think there is a list of them anywhere yet, but they are not too hard to figure out by analysing the URL of a normal AQP after the search has been returned.

NOTES:

1. To play around with the results while testing the AQP for the results it gives, it can be very handy to have the query form showing with you view the page. To show the query form, put the macro <!--#queryForm--> in the 'Page Content Template'. Then when you want to insert the AQP into a page using javascript, make sure you remove the '#'.

2. If you have double quotes appearing anywhere in your results, this will break the javascript. (I have got into the habit of never including double quotes in headings).


QuickStart
Main Menu
Discussion

Guests
Welcome!
  • Sign Up
  • Logon

  • Search


    This site managed with Conversant, © Copyright 2008 Macrobyte Resources; Unless otherwise stated, content © 2000 - 2005 Mark Morgan
    Site design adapted from a free template at Free Site Templates.