Page 1 of 1

How to change category display based on categ vs. product

Posted: Mon May 11, 2009 9:08 pm
by ZLA
On my category pages, if there are categories / sub categories, I want to display a category grid.
If the category only contains products, then I want a display more like the Category Details page.

I'm guessing I can do something like the following psuedo-code:
// get nodes
if (!nodestypes.contain("Products")) {
[[ConLib:CategoryGridPage2]]
} else {
[[ConLib:CategoryDetailsPage]]
}

I know that's not quite right since it mixes scriplets and code behind. Can someone get me started on how to accomplish this? Thanks in advance.

Re: How to change category display based on categ vs. product

Posted: Tue May 12, 2009 5:31 am
by mazhar
A simple solution could be to manually apply category details page on those categories for which you know that they don't have any sub category and for all other you can have category grid page. Do not use NVelocity as programming alternative, its extensive use can slow down your pages. With NVeclocity you can try following solution

Code: Select all

#set($found = 0)
#foreach($cnode in $Category.CatalogNodes)
#if( $found == 0 && $cnode.CatalogNodeType == "Category")
#set($found = 1)
#end
#end
#if($found == 1)
[[ConLib:CategoryGridPage]]
#else
[[ConLib:CategoryDetailsPage]]
#end

Re: How to change category display based on categ vs. product

Posted: Tue May 12, 2009 6:15 am
by ZLA
Thanks Mazhar. While philosophically I prefer the programmatic solution, I've only got about 100 categories in 2 levels. So the configuration solution is very doable.

As a follow-up question, I've seen that same disclaimer about using nVelocity. Can you explain why it is slower than normal .NET programming?

Re: How to change category display based on categ vs. product

Posted: Tue May 12, 2009 6:24 am
by mazhar
NVelocify just replaces its constructs with values from different objects. Basically it is a Template Engine and its purpose is to give end user control on display. For example in Email templates different stores could have different names and NVelocity plugs correct name. So if you are going to target some complex programming solution then it would be better to write a new ConLib instead of writing a bunch of NVelocity code, which will first run by .NET to populate NVelocity parameters and initialize NVeclocity and then further processed by NVelocity to plug correct values.