Xaraya UserAPI Functions

Nov 09, 2008 - TechTrench

Graphic related to Xaraya UserAPI Functions

Developing websites with Xaraya’s default set of module blocks is rather limited. Use Xaraya’s UserAPI functions for more flexibility.

Most Xaraya modules provide a set of user functions within the modules’ userapi folders. A module’s available blocks use these functions to provide some default functionality, but the blocks are often limited and can only be configured and used based on a set of pre-defined criteria.

If you wanted to place, say, the five most recent articles, spanning all of your configured pubtypes, somewhere on your website’s home page, you could setup an articles block from within the blocks module, sort the articles based on publication date, assign it to a group, and then call it in the page this way:

<xar:block instance="name" type="topitems" />

This works fine and is nicely functional, but what happens when down the road you have several publication types and multiple blocks for each one. It can be difficult identifying which block to place and where to place it.

Another solution is to use the same <xar:block/> tag and place a block directly without having to set one up in the configuration screens. The code below will place a block directly where you need it, and you don’t have to pre-configure it first as in the example above. Just make sure you have the right templates, center.xt for the group and topitems-topfive.xt for the block:

<xar:block module="articles" type="topitems" title="Recent Articles" state="3" numitems="5" toptype="pubdate" dynamictitle="false" name="recent_articles" template="center;topfive" />

Probably the best solution I’ve found to do things like this with blocks on occasion is to use the user functions from the articles module (or any module that provides them) directly. A module’s user functions are found in the userapi folder, inside the module’s main folder.

<xar:set name="anyvar">xarmodapifunc('articles','user','getall',array('fields' => array('title','aid','pubdate','pubtypeid','status','summary','body','dynamicdata'), 'status' => array(2,3), 'numitems' => '5'))</xar:set>

Here, the function I use is the getall function (getall.php) in the articles userapi folder. All of the variables available to use are listed in the top of the getall file. It’s just a matter of using the syntax correctly and pulling what you need from the articles and dynamicdata fields. This is where the advantage is. You can customize what content you need for any particular placement by indicating so in the “fields” array. What you do with the output of the result set is also customizable.

These examples show the flexibility Xaraya provides in terms of manipulating content with various block references and methods for placing blocks. Mix them up, identify where it’s best to use a function directly vs. the more systematic block calls.

article with others

Comments

Xaraya UserAPI Functions
Comment posted by nyback on December 08, 2008 - Reviewer's website

good article!! hope there will be more like this.

Read complete comment
Xaraya UserAPI Functions
Comment posted by Neil on February 17, 2009

Very nice article!! Well written. :)

Read complete comment
Xaraya UserAPI Functions
Comment posted by free ebook on June 30, 2009 - Reviewer's website

I thought I would leave my first comment. I don’t know what to say except that I have enjoyed reading. Nice blog. I will keep visiting this blog very often.

Read complete comment
Have you used Xaraya UserAPI Functions? What is your opinion?
Name or Screen Name:* (required)
Your Website (links back):
Overall Performance Rating: 5 (outstanding) to 1 (very poor)
Efficiency Rating: 5 (outstanding) to 1 (very poor)
Ease of Use Rating: 5 (outstanding) to 1 (very poor)
Your Comment Title:
Your comment:
Textile markup is active... Textile reference >.

Keywords

Browse Related TechTrench Content by These Topics:

Module APIs

Xaraya Blocks

XarModApiFunc

Related Articles