[Solved]: Custom fields in News Module

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
ehaldur
Forum Members
Forum Members
Posts: 23
Joined: Thu Apr 26, 2012 4:23 pm

[Solved]: Custom fields in News Module

Post by ehaldur »

Hi all.

Does anybody knows, how I can activate or hide different custom fields in News module?

Each my entry has custom fields for two different language versions of my site. I just wanted to show one of them with the one template and other with the second... But all the custom fields are displayed as one - i can't hide something.

Is it possible to add a different name to each custom field and manage them in template?


Thx for help.
Last edited by ehaldur on Sat Feb 02, 2013 9:03 am, edited 1 time in total.
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3483
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: Custom fields in News Module

Post by velden »

Here an example of a summary template I once made:

Code: Select all

<!-- Start News Display Template -->
{*debug*}
{foreach from=$items item=entry name=loop}


<div class="{cycle values="contentleft,contentright"}">
<div class="txt"><h1>{$entry->title|cms_escape}</h1>
<h3>{$entry->fieldsbyname.datum->value}</h3>{$entry->content}</div>

{if isset($entry->fields)}
  {if $entry->fieldsbyname.afbeelding1}
<a class="fancybox-thumbs" data-fancybox-group="thumb" href="{$entry->file_location}/{$entry->fieldsbyname.afbeelding1->value}">
       {supersizer path="`$entry->file_location`/`$entry->fieldsbyname.afbeelding1->value`" strip_tags=true crop="true" width=325 height=185 protect=false alt="" width_attr="325" height_attr="185"}</a>
{/if}
{/if}
</div>

{if !$smarty.foreach.loop.last}
<div class="divider"></div>
{/if}
{/foreach}
<!-- End News Display Template -->
Custom fields are: 'datum' and 'afbeelding1'.

This should give you an idea how to use custom fields
(M)
Forum Members
Forum Members
Posts: 118
Joined: Tue Mar 18, 2008 11:43 pm

Re: [Solved]: Custom fields in News Module

Post by (M) »

I also want to activate or hide different custom fields in the detail template of the News module? The above solution is not working for me.

This is de code it made;

{if $entry->fieldsbyname.Firstimage != ''}
<div class="image_content_block">
<div class="NewsDetailField">
<img src="{$entry->file_location}/{$entry->fieldsbyname.Firstimage->value}" />
</div>
</div>
{/if}

A want it work like this; if there is no image given in the Custom field "Firstimage" than the div "image_content_block" must hide.
Last edited by (M) on Sat Feb 02, 2013 10:32 pm, edited 1 time in total.
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3483
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: Custom fields in News Module

Post by velden »

I guess you could use the {debug} tag at the beginning of your news-template (allow popups) and then have a look which variables are available and what their values are.
User avatar
manuel
Power Poster
Power Poster
Posts: 353
Joined: Fri Nov 30, 2007 9:15 am

Re: Custom fields in News Module

Post by manuel »

Dear (M),

Please try replacing

Code: Select all

{if $entry->fieldsbyname.Firstimage != ''}
with

Code: Select all

{if $entry->fieldsbyname.Firstimage->value}
The same should apply to you Velden:
Please try replacing

Code: Select all

{if $entry->fieldsbyname.afbeelding1}
with

Code: Select all

{if $entry->fieldsbyname.afbeelding1->value}
Greetings,
Manuel
Do you like your open source cms? Buy from the CMSMS partners || Donate
(M)
Forum Members
Forum Members
Posts: 118
Joined: Tue Mar 18, 2008 11:43 pm

Re: [Solved]: Custom fields in News Module

Post by (M) »

I'm no good in scripting and see a lot if i use {debug}...

Mainly a want to use something like this (but it's not working);

<div class="image_content_block">
{if isset($entry->fieldsbyname.ImageVideo2)}
{foreach from=$entry->fields item='field'}
{if $field->type == 'Text Area'}
{eval var=$fieldsbyname.ImageVideo2->value}
{/if}
{/foreach}
{/if}
</div>

In combination with several 'Text Area' Field Definitions and put it several times in the detail template to have more than one content box to put images, video and text.
If there is no input of images, video or text than the 'image_content_block' div must disappear or hidden.

Maybe some one would help.

@manuel; thanx, but it do not work.
Last edited by (M) on Sat Feb 02, 2013 10:31 pm, edited 1 time in total.
(M)
Forum Members
Forum Members
Posts: 118
Joined: Tue Mar 18, 2008 11:43 pm

Re: [Solved]: Custom fields in News Module

Post by (M) »

Dear Manual,

I was to fast in my opinion. When i clean up the code and use this:

Code: Select all

{if $entry->fieldsbyname.Firstimage->value}
	<div class="image_content_block">
		<img src="{$entry->file_location}/{$entry->fieldsbyname.Firstimage->value}" alt='' />
	</div>
{/if}
it works!

Now when i put nothing in the field "Firstimage" it's display nothing. Just what i need.

Thanx again!
Last edited by (M) on Sat Feb 02, 2013 10:31 pm, edited 1 time in total.
User avatar
manuel
Power Poster
Power Poster
Posts: 353
Joined: Fri Nov 30, 2007 9:15 am

Re: Custom fields in News Module

Post by manuel »

Dear (M),

hehe, thx for confirming! :)

ehaldur? Did you get your issue resolved as well?
The only thing you need to is create something like this:

if language=EN && $entry->fieldsbyname.**ENfieldDefinitionName**->value
show the EN field definition...
elseif language=FR && $entry->fieldsbyname.**FRfieldDefinitionName**->value
show the FR field definition...

If your issue has also been resolved... Please add [Solved] to the subject of the first post. If not... ask a question ;D

Greetings,
Manuel
Do you like your open source cms? Buy from the CMSMS partners || Donate
ehaldur
Forum Members
Forum Members
Posts: 23
Joined: Thu Apr 26, 2012 4:23 pm

Re: Custom fields in News Module

Post by ehaldur »

Thank you all!

fieldsbyname. works great.
(M)
Forum Members
Forum Members
Posts: 118
Joined: Tue Mar 18, 2008 11:43 pm

Re: [Solved]: Custom fields in News Module

Post by (M) »

@ manuel
Thanx any way.
For now I use labeling for news items in different languages.
Post Reply

Return to “Modules/Add-Ons”