Accessing news field definitions in template

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Locked
spthomas
New Member
New Member
Posts: 3
Joined: Thu Feb 18, 2010 6:17 pm

Accessing news field definitions in template

Post 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?
spthomas
New Member
New Member
Posts: 3
Joined: Thu Feb 18, 2010 6:17 pm

[solved] Re: Accessing news field definitions in template

Post by spthomas »

A friend of mine figured it out:

Importance: {$entry->fieldsbyname.importance->value}
User avatar
manuel
Power Poster
Power Poster
Posts: 354
Joined: Fri Nov 30, 2007 9:15 am

Re: Accessing news field definitions in template

Post 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
Do you like your open source cms? Buy from the CMSMS partners || Donate
User avatar
manuel
Power Poster
Power Poster
Posts: 354
Joined: Fri Nov 30, 2007 9:15 am

Re: Accessing news field definitions in template

Post 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
Do you like your open source cms? Buy from the CMSMS partners || Donate
User avatar
manuel
Power Poster
Power Poster
Posts: 354
Joined: Fri Nov 30, 2007 9:15 am

Re: Accessing news field definitions in template

Post 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
Do you like your open source cms? Buy from the CMSMS partners || Donate
User avatar
manuel
Power Poster
Power Poster
Posts: 354
Joined: Fri Nov 30, 2007 9:15 am

Re: Accessing news field definitions in template

Post 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
Do you like your open source cms? Buy from the CMSMS partners || Donate
Locked

Return to “CMSMS Core”