Xaraya UserAPI Functions
Nov 09, 2008 - TechTrench
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.
TechTrench Blog Archives
- TechTrench (Home) >
- Web Development Technologies >
- Subscribe to Content Management >
- Technical Communication Tools >






good article!! hope there will be more like this.
Very nice article!! Well written. :)
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.