CTLModuleMaker -> Display Products by Group

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Locked
jonnieb
Forum Members
Forum Members
Posts: 16
Joined: Thu Sep 11, 2008 10:32 pm

CTLModuleMaker -> Display Products by Group

Post by jonnieb »

Hi there!

I use the new version of CTLModuleMaker and I really like it! Great job!
I created a module with this structure:

Category -> Subcategory -> Products

What I would like to have is a template which lists all Products but grouped by Subcategory. E.g.

Subcategory 1
  Product 1
  Product 2
Subcategory 2
  Product 1
  Product 2
  Product 3

Is this possible?

Best,
Markus
User avatar
plger
Forum Members
Forum Members
Posts: 196
Joined: Wed Oct 15, 2008 10:38 am

Re: CTLModuleMaker -> Display Products by Group

Post by plger »

Yes.

create the template "list_products" :

Code: Select all

<ul>
{foreach from=$itemlist item="item"}
   <li>{$item->detaillink} (or {$item->name} if you prefer)</li>
{/foreach}
</ul>
and the template "list_subcategories" :

Code: Select all

<ul>
{foreach from=$itemlist item="item"}
   <li>{$item->name}{cms_module module="modulename" what="product" listtemplate="list_products" forcelist="1"}</li>
{/foreach}
</ul>
then in your page call the subcategories with the appropriate template :
{cms_module module="modulename" what="subcategory" listtemplate="list_subcategories"}

(of course, make sure the names of the module and levels are correct)
(you could repeat the logic to include the categories in the list)

If you created your module using a recent version of CTLModuleMaker, you should think about using the "sitemap" action, which is made to output a cross-level list (it does so in only one query, and as such is quite faster when you have a lot of levels/items), although it allows less customization.

Pierre-Luc
louisk
Forum Members
Forum Members
Posts: 89
Joined: Wed May 30, 2007 7:40 pm

Re: CTLModuleMaker -> Display Products by Group

Post by louisk »

Hi, I'm trying to achieve the same thing but can't get it to work.
I've made a curriculum vitae builder.
First you add a section header (e.g. personalia/hobbies/work experience)
Then you can add a detail, which has to fields:
- label (e.g. birth date)
- detail (e.g. April 21 1983)

On my page I would like to display the following:

Personalia
Birth date: April 21 1983
Birth place: Cape-Town

Work experience
2000-2005: Photoshop expert
2005-2009: Chillin

etc. etc.

At the moment I'm getting the wrong output, namely:

Personalia
Birth date: April 21 1983
Birth place: Cape-Town
2000-2005: Photoshop expert
2005-2009: Chillin

Work experience
Birth date: April 21 1983
Birth place: Cape-Town
2000-2005: Photoshop expert
2005-2009: Chillin

As you can see, the headings display correctly, but the labels and details are being repeated.

I'm calling the module in the page template like this:

Code: Select all

{cms_module module="cvbuilder" what="heading" listtemplate="heading"}
My headings template is:

Code: Select all

{foreach from=$itemlist item="item"}
<div class="cv_category">
	<h3>{$item->name}</h3>
	<table>
		<tbody>
{cms_module module="cvbuilder" what="detail" listtemplate="list_default"}
		</tbody>
	</table>
</div>
{/foreach}
And the details template is:

Code: Select all

{foreach from=$itemlist item="item"}
<tr>
	<td><span>{$item->label}</span></td>
	<td>{$item->detail}</td>
</tr>
{/foreach}
So, what am I doing wrong?
Home you can help.
User avatar
plger
Forum Members
Forum Members
Posts: 196
Joined: Wed Oct 15, 2008 10:38 am

Re: CTLModuleMaker -> Display Products by Group

Post by plger »

Headings template should be :

Code: Select all

{foreach from=$itemlist item="item"}
<div class="cv_category">
	<h3>{$item->name}</h3>
	<table>
		<tbody>
{cms_module module="cvbuilder" what="detail" listtemplate="list_default" parent=$item->alias}
		</tbody>
	</table>
</div>
{/foreach}
But for performance reasons, I would suggest using the solution shown in the FAQ :

Create the following template (which I'll call "order_by_parents"):

Code: Select all

			<ul>
			{assign var="parentflag" value=false}
			{foreach from=$itemlist item="item"}
				{if $item->parent_name != $parentflag}
					{if $parentflag}</ul></li>{/if}
					<li>{$item->parent_name}<ul>
					{assign var="parentflag" value=$item->parent_name}
				{/if}
				<li>{$item->label}: {$item->detail}</li>
			{/foreach}
			</ul>
and call it using {cms_module module="cvbuilder" what="detail" listtemplate="order_by_parents" orderby="parent"}
louisk
Forum Members
Forum Members
Posts: 89
Joined: Wed May 30, 2007 7:40 pm

Re: CTLModuleMaker -> Display Products by Group

Post by louisk »

Thanks! it works great!
However, the sorting isn't working. I would like the order of the headings and the items to be determined by the order in the admin (with ordering arrows).
How would I do this? since the orderby param is already used?
User avatar
plger
Forum Members
Forum Members
Posts: 196
Joined: Wed Oct 15, 2008 10:38 am

Re: CTLModuleMaker -> Display Products by Group

Post by plger »

I've just looking at my code again and noticed that if you leave the orderby parameter empty, it should behave the way you want it.

Code: Select all

{cms_module module="cvbuilder" what="detail" listtemplate="order_by_parents"}
Try it out, and if it doesn't work I'll show you another solution.
plger
Locked

Return to “Modules/Add-Ons”