[Solved]: Custom fields in News Module
[Solved]: Custom fields in News Module
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.
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.
Re: Custom fields in News Module
Here an example of a summary template I once made:
Custom fields are: 'datum' and 'afbeelding1'.
This should give you an idea how to use custom fields
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 -->
This should give you an idea how to use custom fields
Re: [Solved]: Custom fields in News Module
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.
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.
Re: Custom fields in News Module
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
Dear (M),
Please try replacingwith
The same should apply to you Velden:
Please try replacingwith
Greetings,
Manuel
Please try replacing
Code: Select all
{if $entry->fieldsbyname.Firstimage != ''}
Code: Select all
{if $entry->fieldsbyname.Firstimage->value}
Please try replacing
Code: Select all
{if $entry->fieldsbyname.afbeelding1}
Code: Select all
{if $entry->fieldsbyname.afbeelding1->value}
Manuel
Do you like your open source cms? Buy from the CMSMS partners || Donate
Re: [Solved]: Custom fields in News Module
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.
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.
Re: [Solved]: Custom fields in News Module
Dear Manual,
I was to fast in my opinion. When i clean up the code and use this:it works!
Now when i put nothing in the field "Firstimage" it's display nothing. Just what i need.
Thanx again!
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}
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.
Re: Custom fields in News Module
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
Greetings,
Manuel
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
Greetings,
Manuel
Do you like your open source cms? Buy from the CMSMS partners || Donate
Re: Custom fields in News Module
Thank you all!
fieldsbyname. works great.
fieldsbyname. works great.
Re: [Solved]: Custom fields in News Module
@ manuel
Thanx any way.
For now I use labeling for news items in different languages.
Thanx any way.
For now I use labeling for news items in different languages.