Journal

Xaraya
Browse in : All > Categories > Xaraya

Note: when you create a new publication type, the articles module will automatically use the templates user-display-[publicationtype].xd and user-summary-[publicationtype].xd. If those templates do not exist when you try to preview or display a new article, you'll get this warning :-)

Title: Xaraya: using xarModURL to create links

Author: jrojr

Date: September 14, 2005 3:36:42 AM or Wed, 14 September 2005 03:36:42

Summary: 

In Xaraya, hardcoded links are rarely a good choice for creating links to internal objects. The Xaraya function xarModURL() allows for the creation of dynamic links, which adjust as a site changes.

Body: 

Navigational schemes for the majority of websites out there include some form menu that lists every section available to the user from the website. In most cases, these are internal links that lead to different content under the same domain.

With CMS software such as Xaraya, there are options to change URL formats at will, which in turn will cause all links on the website to change, including those in your navigation menu. This is bad news if you've decided to hard code the links in your navigation menu, because you'll then be forced to re-edit any templates that have those hardcoded links in them.

In order to prevent you from having to do such tedious work, Xaraya provides a utility function that creates links for you on-the-fly.

The Scenario

Let's say you plan on including the following sections in your navigation menu:

First Step

Links to each of these can be made very easily. The first step is to put the links in an unordered list:

<ul>
    <li>Home</li>
    <li>News</li>
    <li>Forum</li>
</ul>

You'll end up with something that looks similar to this:

For those of you who are unfamiliar with web standards, this may look a bit odd to you. For a thorough explanation of why this is implemented as an unordered list, take a look at the article CSS Design: Taming Lists over at A List Apart.

Second Step

The second step is to place links inside of these lists:

<ul>
    <li><a href="#">Home</a></li>
    <li><a href="#">News</a></li>
    <li><a href="#">Forum</a></li>
</ul>

The result looks something like this:

Adding xarModURL

Now, we can add xarModURL():

<ul>
    <li><a href="#xarModURL()#">Home</a></li>
    <li><a href="#xarModURL('articles', 'user', 'view', array('ptid' => 1))#&quot;&gt;News</a></li>
    <li><a href="#xarModURL('xarbb', 'user', 'main')#">Forum</a></li>
</ul>

In the first list item, we've made a call to xarModURL() with no parameters. Since there are no parameters, by default the link created by this call will lead to the front page of the website.

In the second list item, we've made a call to xarModURL with a number of parameters:

In the third list item:

Depending on how your installation is configured, the actual links could look like any of the following (roll your mouse over the links to see the URLs):

Short URLs enabled, index.php removed from URL path
Short URLs enabled, index.php retained in URL path
Short URLs disabled

Conclusion

No you've got a nice unordered list with links that are automagically tailored to your site's configuration — and if you decide to change this configuration in the future, all links you've created with xarModURL will automatically be updated. Now all that' sleft is to style your navigation menu to make it look like a navigation menu. The aforementioned Taming Lists article from A List Apart will be of great use in helping you make your lists pretty.

Notes: 

More fields may be available via dynamicdata ..