Field Definitions in News and Blog

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Post Reply
carasmo
Power Poster
Power Poster
Posts: 506
Joined: Thu Feb 08, 2007 6:11 pm
Location: Florida

Field Definitions in News and Blog

Post by carasmo »

carasmo wrote:

Code: Select all

{if $entry->fieldsbyname.mainimage != ''} {*if the field is not empty*}

{$entry->fieldsbyname.mainimage->value}

{/if}
Then you put the one with the -> value in the image tag

if the field is Main Image (not mainimage) note the caps and the space, then that's a different matter.

Code: Select all

{assign var='mainimage' value='Main Image'}
{if $entry->fieldsbyname.$mainimage != ''}
{$entry->fieldsbyname.$mainimage->value}{/if}
if the field is Mainimage then

Code: Select all

{if $entry->fieldsbyname.Mainimage != ''}
{$entry->fieldsbyname.Mainimage->value}{/if}
Notice it's case sensitive mainimage is not Mainimage and Main Image is not main_image. You would use the appropriate syntax for the job.
applejack
Power Poster
Power Poster
Posts: 1015
Joined: Fri Mar 30, 2007 2:28 am
Location: London

Re: Field Definitions in News and Blog

Post by applejack »

Are you sure you are checking for if a value exists or if just the field name exists.

Should it not be e.g.

Code: Select all

{if $entry->fieldsbyname.Mainimage->value}
do something
{/if}
Though depends on the field type and default value.
carasmo
Power Poster
Power Poster
Posts: 506
Joined: Thu Feb 08, 2007 6:11 pm
Location: Florida

Re: Field Definitions in News and Blog

Post by carasmo »

If there's nothing in the field, it'd print the container like an empty p tag, so if the value exists then do it. If the image exists, then load the figure tag, etc.,

Haven't tried what you wrote, got the if not empty from elsewhere...
applejack
Power Poster
Power Poster
Posts: 1015
Joined: Fri Mar 30, 2007 2:28 am
Location: London

Re: Field Definitions in News and Blog

Post by applejack »

Ok just trying suggest a potential shorthand version. Try it.
carasmo
Power Poster
Power Poster
Posts: 506
Joined: Thu Feb 08, 2007 6:11 pm
Location: Florida

Re: Field Definitions in News and Blog

Post by carasmo »

Thanks! I will.
Post Reply

Return to “Tips and Tricks”