• twitter image
  • facebook image
  • youtube image
  • linkedin image
Language: CMS made Simple Czech Site Zur deutschsprachigen Supportseite Site francophone Sitio en Castellano CMSMS - Magyarország CMSMS -  ???????
Pages: [1]
  Print  
Author Topic: Displaying custom fields in Products module  (Read 410 times)
0 Members and 1 Guest are viewing this topic.
klontjes
New Member


Karma: 0
Offline Offline

Posts: 3


« on: 06 Mar 2010, 15:17 »

I used the Products module for a projects page (had it in 'News' first, but I ran into a few dead ends with that one) and I'm using a fair bit of custom fields. It should be simple to use those custom fields in any of the templates provided, but... I can't seem to figure it out.

In the default summary template it says:
Quote
   {*
     the summary template has access to custom fields via the $entry->fields hash
     and to categories via the $entry->categories array of objects.  Also
     attribute information is available via $entry->attributes.
     you should use the get_template_vars and the print_r modifier to see
     what is available
    *}

I've searched extensively for something on the $entry->fields hash, but no luck.

It seems to me the custom fields are in an array within an array, so after a bit of effort and copy-pasting I came up with:

{foreach from=$entry->fields key='name' item='field'}
 {if $field->name == 'summary'}
   {$field->value}<br />
  {/if}
 {if $field->name == 'city'}
   {$field->value}
  {/if}
{/foreach}


That works, but it also doesn't seem very efficient.
Is there a shorter/better/more effective way of displaying those custom fields?

Thanks,

Peter.
Logged
osxfil
Forum Members
**

Karma: 0
Offline Offline

Posts: 76



« Reply #1 on: 07 Mar 2010, 02:56 »

Hi, you can use this:
Code:
{$entry->fields.name_of_field->value}
Logged
klontjes
New Member


Karma: 0
Offline Offline

Posts: 3


« Reply #2 on: 10 Mar 2010, 10:29 »

Thanks osxfil...

I haven't had the time to look into it as far as I would have wished, but the code suggested doesn't get rid of the foreach loop needed to find stuff within the array right? Anyway, I couldn't get it to work.

In the mean time I found:
http://www.smarty.net/manual/en/language.syntax.variables.php
which should prove helpful.

(just updating this thread so it might be of help to someone in the future (and until I can add 'SOLVED' to the title))
Logged
curlypinky
Forum Members
**

Karma: 0
Offline Offline

Posts: 46


« Reply #3 on: 30 Apr 2010, 05:15 »

Thanks so much osxfil, your post was exactly what I was looking for!

{$entry->fields.name_of_field->value}

Just to augment the info, in the case of images:
{$entry->fields.name_of_field->value} is the filename for the main image
{$entry->fields.name_of_field->thumbnail} is the filename for the thumbnail
{$entry->fields.name_of_field->preview} is the filename for the preview image

klontjes - No foreach loop needed, perhaps you were using the wrong field name? name_of_field corresponds with the alpha numeric name you set for each field, not the prompt.
Logged
Pages: [1]
  Print  
 
Jump to: