chapter31

development in a land far far away…

at the moment

History is not what happened. History is what was written down.

Note: This is for FarCry v3 which is a bit old now but should work for v5 :)

Sometimes when using FarCry I have a need to find an occurance of a page “type” which sits somewhere above where I currently am in the the navigation hierachy.

Say I want to find the “VehicleType” page (which could be Car or Bike etc) above where I am in the navigation hierachy as listed below (when I’m on the “Models” page):

  • Home
    • Vehicles
      • Bike
      • Car
        • Sedans
          • Models
        • Wagons

I want to know whether I’m in the “Car” or “Bike” part of the navigation tree and I want the content object of that page.

There are a couple of ways to do this, using categories (tags) would be one way. Another is to simply look for an occurance of my type (VehicleType) in the tree above the current page you’re on.

The following function will do just that, just pass in the request.navId of the page you’re on (Models), the typename and displayMethod you’re looking for (VehicleType).

For example:

Note that the “nLevel” argument in the function allows you to skip the ancestor nodes you know you’re not interested in such as “Root” and “Home”.

Hope this helps some people.


Related Pages

Leave a Reply