Page 1 of 1

Accessing news field definitions in template

Posted: Tue Sep 14, 2010 12:23 am
by spthomas
If I create a custom field called "importance" for my news column, how can I get at that variable in the template?

I'm thinking something along the lines of:

{foreach from=$items item=entry}
{$entry|@print_r}
Importance: {$entry.fieldsbyname.importance.value}
{/foreach}

...but that doesn't work. The print_r statement shows the array, but what is the syntax for getting at specific elements?

[solved] Re: Accessing news field definitions in template

Posted: Wed Sep 15, 2010 11:04 am
by spthomas
A friend of mine figured it out:

Importance: {$entry->fieldsbyname.importance->value}

Re: Accessing news field definitions in template

Posted: Thu Nov 04, 2010 3:24 pm
by manuel
Thx for posting this Thomas!!!!

Additional remark: if you use capitals in the Field Definition name, don't use them to call the value or it won't work...
Just letting everyone know to hopefully save someone somewhere some timeĀ  ;D

ex: I created the Field Definition "Comment"
Code that doesn't work
{$entry->fieldsbyname.Comment->value}
{$entry->fieldsbyname.Comment->name}

Code that works
{$entry->fieldsbyname.comment->value}
{$entry->fieldsbyname.comment->name}

Greetings,
Manuel

Re: Accessing news field definitions in template

Posted: Wed Nov 24, 2010 4:39 pm
by manuel
If you only want to make the custom entries appear only when a value has been filled out, you may use one of the following methods:

Code: Select all

{if $entry->fieldsbyname.comment != ''}A comment has been filled out{/if}

Code: Select all

{if isset($entry->fieldsbyname.comment)}A comment has been filled out{/if}
Greetings,
Manuel

Re: Accessing news field definitions in template

Posted: Fri Dec 03, 2010 5:38 pm
by manuel
I was having some trouble getting the file location URL from the "fieldsbyname"

solution: use the generic file_location in combination with the fieldsbyname value

Code: Select all

{$entry->file_location}/{$entry->fieldsbyname.record_cover_front->value}
Greetings,
Manuel

Re: Accessing news field definitions in template

Posted: Fri Dec 03, 2010 5:59 pm
by manuel
If you use spaces in your Field Definition name, these should be replaced with underscores when calling the value etc...

Field Definition name: Record cover front
should become fieldsbyname.record_cover_front

Greetings,
Manuel