|
From: Immanuel Y. <no...@as...> - 2005-08-12 18:00:45
|
On Fri, Aug 12, 2005 at 10:16:09AM -0700, Sook Jung wrote:
> Hello,
>
> I'm trying to make a generic cross-reference in
> feature object. When I use feature name in the url it
> works. The problem is that some of the features have
> aliases and when they do have aliases I need to use
> aliases instead of feature name.
>
> So feature_name works by something like this.
> some url=[% object.feature_name %]
>
> Aliases doesn't work when I tried something like this.
> [% FOREACH id=object.aliases %]
> some url=[% id %]
> [% END %]
object.aliases returns an array. If you want to handle all the
elements it returns, you can do something like:
[% SET names = [object.feature_name] %]
[% names.push(a.alias) FOREACH a IN object.aliases %]
some url=[% names.join(',') %]
That will catenate the feature_name and aliases to a single string
separated by commas, then pass it to the external URL. The external
URL must, of course, know how to handle a comma-separated list.
If you know you'll only ever have one element, you can use:
[% FOREACH a=object.aliases %]
some url=[% a.alias %]
[% END]
If you have multiple elements, the above construct will return
multiple URLs, each on their own line. The displayed xref name will
be the same, however, which can be confusing to end users.
> Eventually what I want to do is to use feature name in
> the url when aliases doesn't exist, and use aliases
> when they do.
>
> [% IF some condition %] ## if aliases exist
> [% FOREACH id=object.aliases %]
> some url=[% id %]
> [% END %]
> [% ELSE %]
> some url=[% object.feature_name %]
> [% END %]
I believe that testing simply testing an array will return FALSE if
the array has no elements. So you can do something like:
[% IF object.aliases %]
[% FOREACH a=object.aliases %]
some url=[% a.alias %]
[% END]
[% END %]
[% ELSE % ]
some url=[% object.feature_name %]
[% END %]
> If it's possible, I want to include map_id in the IF
> clause so that I can restrict this into some selected
> maps.
>
> What is the correct syntax to do this?
I assume you meant map_set_id?
[% IF object.map_set_aid == 'ID#' %]
(do stuff)
[% END %]
Noel
--
Immanuel Yap <iv...@co...>
|