Page 1 of 1

[Solved]: Custom fields in News Module

Posted: Sat Jan 26, 2013 4:10 pm
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.

Re: Custom fields in News Module

Posted: Sat Jan 26, 2013 6:20 pm
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

Re: [Solved]: Custom fields in News Module

Posted: Thu Jan 31, 2013 1:28 am
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.

Re: Custom fields in News Module

Posted: Thu Jan 31, 2013 9:20 am
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.

Re: Custom fields in News Module

Posted: Thu Jan 31, 2013 3:59 pm
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

Re: [Solved]: Custom fields in News Module

Posted: Thu Jan 31, 2013 5:07 pm
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.

Re: [Solved]: Custom fields in News Module

Posted: Thu Jan 31, 2013 11:55 pm
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!

Re: Custom fields in News Module

Posted: Fri Feb 01, 2013 9:33 am
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

Re: Custom fields in News Module

Posted: Sat Feb 02, 2013 9:02 am
by ehaldur
Thank you all!

fieldsbyname. works great.

Re: [Solved]: Custom fields in News Module

Posted: Sat Feb 02, 2013 10:30 pm
by (M)
@ manuel
Thanx any way.
For now I use labeling for news items in different languages.