Page 1 of 1

Catalog Module & formatting template with Smarty

Posted: Sun Oct 21, 2007 1:13 pm
by peedub
Hi there,

I'm using the catalog module (v.0.5.5, http://dev.cmsmadesimple.org/) to for a client's online product catalog.

I have added an item attribute named "price" - this adds the field "price" to the "add content" page, allowing the client/admin to input a price amount when adding/modifying a product, or "catalog item".

What I would like to do is format that attribute, "price", so when the client/admin inputs a price (such as, "1000") via the CMS, it comes out on the front-end formatted in strike-through, dollar sign ($) added in front and with the following words after the given price, "(contact us for the best price)", like this:

Code: Select all

<s>$1000</s><span>(contact us for the best price)</span>
Right now, I can manually format the price on the front-end by putting the above code in the "price" attribute field via the back-end, but this will be problematic for the client to do.

What I want to do is make every "price" field in a category-item page type to be formated like above, but the problem is that the "price" attribute is loaded to the front-end via a loop in the catalog-item template, so it's hard to edit a specific attribute.

This is a snippet from the category-item template, which loads the attributes automatically:

Code: Select all

<div class="catalog_item">
{section name=at loop=$attrlist}
<div class="item_attribute_name">{$attrlist[at].name}</div>
<div class="item_attribute_val">{eval var=$attrlist[at].key}</div>
<br />
{/section}
Using the above code, is it possible to keep the loop to load the attributes but use PHP or Smartytags (I'm unfamiliar with both of these 'languages') to say something like;
[pseudo-code] if the attribute, "price", is not blank (ie, a price is given), then add "$" before value and "(contact us for the best price)" after value, else, display the text, "(contact us for the best price)" [/pseudo-code]

There are also the following variables to use:
Category Template Variables
{$title}, {$notes}, {$prev}, {$prevurl}, {$navstr}, {$next}, {$nexturl}, {$items}, {$image_1_url}, {$image_thumb_1_url}, {$src_image_1_url}, {$image_url_array}, {$src_image_url_array}, {$image_thumb_url_array}
$items array contents:
$items[].title, $items[].link, $items[].image, $items[].attrname


Is this method possible via the template alone? Or will I need to go in and modify the catalog module files?

Could someone please give me an example of what code would make it work via the template, if possible?

Thank you in advance.

Re: Catalog Module & formatting template with Smarty

Posted: Sun Oct 21, 2007 10:36 pm
by peedub
Wow, I've gotten somewhere! But not quite there, yet...

Code: Select all

{section name=at loop=$attrlist}
<div class="item_attribute_name">{$attrlist[at].name}
{if $price != ''}
   <s>${$price}</s> (contact us for the best price)
{else}
   (contact us for the best price)
{/if}
</div>
<div class="item_attribute_val">{eval var=$attrlist[at].key}</div>
<br />
{/section}
Turns out like this:
Notes $729 (contact us for the best price)

Model $729 (contact us for the best price)
HRU19R

Price $729 (contact us for the best price)
729


And

Code: Select all

{section name=at loop=$attrlist}
<div class="item_attribute_name">{$attrlist[at].name}
{if $attrlist[at].name == '$attrlist[at].price'}
{if $price != ''}
   <s>${$price}</s> (contact us for the best price)
{else}
   (contact us for the best price)
{/if}
{/if}
</div>
{/section}
Turns out like this:
Notes
Model
Price


I think this is about as far as my programming knowledge can take me...

Re: Catalog Module & formatting template with Smarty

Posted: Wed Oct 24, 2007 3:37 pm
by peedub
*bump*, any ideas?

Re: Catalog Module & formatting template with Smarty

Posted: Wed Oct 24, 2007 3:55 pm
by calguy1000
try this:

Code: Select all

{section name=at loop=$attrlist}
{if $attrlist[at].name == 'price'}
<s>{$attrlist[at].key}</s><span>(contact us for the best price)</span>
{else}
<div class="item_attribute_name">{$attrlist[at].name}</div>
<div class="item_attribute_val">{eval var=$attrlist[at].key}</div>
{/if}
<br />
{/section}

Re: Catalog Module & formatting template with Smarty

Posted: Thu Oct 25, 2007 8:20 am
by peedub
calguy1000 wrote: try this:

Code: Select all

{section name=at loop=$attrlist}
{if $attrlist[at].name == 'price'}
<s>{$attrlist[at].key}</s><span>(contact us for the best price)</span>
{else}
<div class="item_attribute_name">{$attrlist[at].name}</div>
<div class="item_attribute_val">{eval var=$attrlist[at].key}</div>
{/if}
<br />
{/section}
Hi calguy, thank you for your response.

I tried a modified version of what you suggested, this is what it came out like;
Notes
notesnotesnotes

Model
HRU19R

Price
{$price}(contact us for the best price)


It's odd that the text "{$price}" appeared, not the actual value of the "$price".

Anyway, with help I have got it working, i'm using:

Code: Select all

{section name=at loop=$attrlist}
<div class="item_attribute_name">{$attrlist[at].name}</div>
{if $attrlist[at].name == 'Price'}
    <div class="item_attribute_val"><s>${eval var=$attrlist[at].key}</s>(contact us for the best price)</div>
{else}
   <div class="item_attribute_val">{eval var=$attrlist[at].key}</div>
{/if}
{/section}
And do you know what I was doing which was causing most of my problems? Referring to 'Price' in the array as 'price' - not meant to be lower case!

*slaps forehead*. Lesson learnt.

Now I've just got to figure out a way to display the text "contact us for the best price", if a Price is not given, while still displaying the other attributes correctly.