Page 1 of 1

News Module: Calling 'Fields' Indivually in a template

Posted: Thu Feb 07, 2008 1:22 pm
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

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

Posted: Mon Feb 11, 2008 11:11 pm
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

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

Posted: Tue Jul 08, 2008 10:44 am
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?

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

Posted: Tue Jul 08, 2008 10:57 am
by Dr.CSS
How do you mean add images, in the content or summary you can add image like in page edit mode?...

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

Posted: Tue Jul 08, 2008 6:09 pm
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

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

Posted: Mon Feb 07, 2011 6:22 pm
by mediabanana
Just a quick tidbit -if you have '-' dashes in your field names this doesn't work, use '_' underscores instead.

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

Posted: Mon Feb 07, 2011 6:50 pm
by Dr.CSS
You can use the jqery cycle plugin, I've used it many times, for news etc...