News Module: Calling 'Fields' Indivually in a template
Posted: Thu Feb 07, 2008 1:22 pm
An associate had a problem with this and Walkere touched on it briefly in this post but I just want to clarify it:
You can display 'field definitions' individually quite simply.
When you add 'Field definitions' to the news module, by default they are all be displayed with the following code:
Not so great if you want to have different types of news items, or if you want to move those fields about a bit.
To display them on there own, you simply use the smarty syntax {$entry->field_name}, Where 'field_name' is the name of any added field definitions with underscores '_' replacing any spaces.
So, for example, if you enter a field called 'News Author', this could be called in a template using {$entry->news_author}.
If you had an image upload field called 'News Thumbnail', this called be called using, {$entry->news_image} which would output only the name of the uploaded file, eg, 'news-image-01.jpg'.
To take that further you could build an image using the following line:
As the default location for uploads fields is: 'SITEROOT/uploads/news/id3' where the final ID folder is determined by the news item.
Hope this helps out, sorry if this is added elsewhere and thanks again to all those working so hard on the news module, great work.

D
You can display 'field definitions' individually quite simply.
When you add 'Field definitions' to the news module, by default they are all be displayed with the following code:
Code: Select all
{if isset($entry->fields)}
{foreach from=$entry->fields item='field'}
<div class="NewsDetailField">
{if $field->type == 'file'}
<img src="{$entry->file_location}/{$field->value}"/>
{else}
{$field->name}: {eval var=$field->value}
{/if}
</div>
{/foreach}
{/if}
To display them on there own, you simply use the smarty syntax {$entry->field_name}, Where 'field_name' is the name of any added field definitions with underscores '_' replacing any spaces.
So, for example, if you enter a field called 'News Author', this could be called in a template using {$entry->news_author}.
If you had an image upload field called 'News Thumbnail', this called be called using, {$entry->news_image} which would output only the name of the uploaded file, eg, 'news-image-01.jpg'.
To take that further you could build an image using the following line:
Code: Select all
<img src="/uploads/news/id{$entry->id}/{$entry->news_image}" alt="{$entry->title}" width="75" height="75"/>
Hope this helps out, sorry if this is added elsewhere and thanks again to all those working so hard on the news module, great work.

D