Xaraya UserAPI Functions

Nov 9, 2008 - TechTrench

Xaraya UserAPI Functions

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"></xar:block>

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

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.

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.

Comment on this article below.
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 >.
antibotimage  

Can't read it? Click the image again.

(case sensitive)


Browse Related TechTrench Content by These Topics:

Module APIs

Xaraya Blocks

XarModApiFunc

Xaraya UserAPI Functions

Xaraya UserAPI Functions

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