News Module: Calling 'Fields' Indivually in a template

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Post Reply
User avatar
myshko
Forum Members
Forum Members
Posts: 102
Joined: Wed Feb 07, 2007 2:36 pm

News Module: Calling 'Fields' Indivually in a template

Post by myshko »

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:

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}
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:

Code: Select all

<img src="/uploads/news/id{$entry->id}/{$entry->news_image}" alt="{$entry->title}" width="75" height="75"/>
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
Last edited by myshko on Thu Feb 07, 2008 1:23 pm, edited 1 time in total.
nivekiam

Re: News Module: Calling 'Fields' Indivually in a template

Post by nivekiam »

Dang it!  I wish I had found this 2 days ago.  I was sooo close.  Didn't realize (or dig into it) that those field names got normalized...

If the field is named PageId use {$entry->pageid}

Thank you for posting this.  I need to browse the Tips&Tricks more often.

DOH:
http://forum.cmsmadesimple.org/index.ph ... 293.0.html
buntrosgali
Forum Members
Forum Members
Posts: 167
Joined: Thu Apr 17, 2008 9:02 pm

Re: News Module: Calling 'Fields' Indivually in a template

Post by buntrosgali »

Hey guys

im looking to add images to my news items, i was looking at this post but i need some guidance on what code to add where in the template or stylesheet to allow me to add images to my news posts.

Can you helP?
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: News Module: Calling 'Fields' Indivually in a template

Post by Dr.CSS »

How do you mean add images, in the content or summary you can add image like in page edit mode?...
buntrosgali
Forum Members
Forum Members
Posts: 167
Joined: Thu Apr 17, 2008 9:02 pm

Re: News Module: Calling 'Fields' Indivually in a template

Post by buntrosgali »

well on my static sites i use a multi news rotational thing called frontpage which is actually created by a joomla guy heres example of what its like

linky

i want to have a similar thing on my cms site, only i would like it setup so that the 4 most recently added news items go into the main page rotator which would look something like this:

linky

you understand?

a friend of mine has succesffully incorporated it into his wordpress site here linky


and i would like to do it with cms


check this post out

http://forum.cmsmadesimple.org/index.ph ... 604.0.html
Last edited by buntrosgali on Tue Jul 08, 2008 9:00 pm, edited 1 time in total.
mediabanana
New Member
New Member
Posts: 2
Joined: Sun Nov 02, 2008 10:56 am

Re: News Module: Calling 'Fields' Indivually in a template

Post by mediabanana »

Just a quick tidbit -if you have '-' dashes in your field names this doesn't work, use '_' underscores instead.
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: News Module: Calling 'Fields' Indivually in a template

Post by Dr.CSS »

You can use the jqery cycle plugin, I've used it many times, for news etc...
Post Reply

Return to “Tips and Tricks”