Category

Extends Object. A Category is a shop's department promoting products and/or sub-categories. A "category" variable containing a Category object is automatically instantiated on URLs governed by the category controller. 

<body>
    <div>
        <h1>{{ category.title }}</h1>
    </div>
</body>

You can gain access to any category within your shop when creating a new Category instance.

<body>
    <div>
        <h1>{{ page.title }}</h1>
    </div>
    
    <?ev var shop = new Category('/shop'); ?>
    
    <h2>{{ shop.title }}</h2>
    <p>{{ shop.description }}</p>
</body>

Note: hard coding URLs in this manner can be open to error if URLs don't exist. If however the URL for a category did exist, but a user changed it within the Product Category settings, Evance will attempt to load the category from its historical URL.

Instantiation

Accessing any Category in your shop can be achieved from anywhere within your website and not just from Product Category governed pages. This can be done by instantiating a new Category object and supplying the page's URL:


<?ev
    // new Category() class method
    var shop = new Category('/shop');
?>

Construct parameters
reference

Type String, Url or Number

The page reference is either a String/Url representing the URL relative to root (e.g. /shop represents your shop's root category), or a Number representing the category.id. 

For international and multi-lingual sites you should use the default URL as the reference for the category and not the localised version. Evance will automatically correct the URL format for you once the Category object is retrieved.



Properties
created

Type Date

The date the page was created represented as a Date object.

description

Type String

The short description for the page represented as a String. Pages do not have a single content block as they may have any number of editable regions. These are represented as fragments that should be rendered via the <ev:editable> tag.

featured

Type Boolean

True if the category is featured, else false.

filterable

Type Boolean

True if the category is has filtering enabled, else false.

hasChildren

Type Boolean

True if the category has sub-categories, else false.

id

Type Number

The system ID for the category.

image

Type Url

An alternative image Url chosen to represent this category. This is called thumbnail for historic reasons, but may be of any size. The image is generally shown on the category page, whilst thumbnail (below) is generally shown on the parent category page.

modified

Type Date

The date the page was last modified as a Date object.

parentId

Type Number

The System ID of the parent category.

template

Type Template

The current Template for the Category.

thumbnail

Type Url

The image Url chosen to represent this category. This is called thumbnail for historic reasons, but may be of any size. The thumbnail is generally shown on the parent category page, whilst image (above) is generally shown on the category page.

title

Type String

The title of the department.

url

Type Url

The URL of the category. If you have an international website this Url will represent the current Locale of your website.



Methods
ancestors()

Alias of Category.parents()

children([Number:limit])

Returns CategoryCollection

Returns all or a number of child categories in order of sequence as they appear within the Product Category tree manager.

descendants()

Returns CategoryCollection

Returns all sub-categories recursively as a single collection excluding the current Category.

filters()

Returns CategoryFilterCollection

Returns all filters for the current category, or the closest category with an assigned filter set. Filters are assigned to a Category within the Product Categories manager.

next([Number:limit])

Returns Category | CategoryCollection | null

Get the next sibling of the current category as a Category object if one exists or null if not. The order of categories is always in order of sequence:asc. When a limit is supplied returns a collection of Category objects.

parent()

Returns Category | null

Returns parent category of the current.

parents()

Returns CategoryCollection

Get the list of parent category objects i.e. the breadrcumbs of the current category up to the top ancestor. Returns a CategoryCollection of page objects with the closest parent first.

prev([Number:limit])

Alias of Category.previous().

previous([Number:limit])

Returns Category | CategoryCollection | null

Returns previous sibling of the current category or null if unavailable. The order of categories is always in order of sequence:asc. When a limit is supplied returns a collection of Category objects.

share()

Returns PageSharer

The PageSharer object allows you to generate social media share links from the Category data.

template()

Returns Template or Null

Returns the Template Object for the Category if a Template has been assigned to the Category, or Null if it uses the default.

topAncestor()

Returns Category

Returns the top shop level Category.

toString()

Returns String

Returns the title of the Category as a representation of the .

tree()

Returns CategoryCollection

Returns all sub-categories recursively as a single collection including the current Category.