Page 1 of 1

Field Definitions in News and Blog

Posted: Thu Aug 02, 2012 5:55 pm
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.

Re: Field Definitions in News and Blog

Posted: Fri Aug 03, 2012 12:40 am
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.

Re: Field Definitions in News and Blog

Posted: Fri Aug 03, 2012 12:44 am
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...

Re: Field Definitions in News and Blog

Posted: Fri Aug 03, 2012 12:54 am
by applejack
Ok just trying suggest a potential shorthand version. Try it.

Re: Field Definitions in News and Blog

Posted: Fri Aug 03, 2012 12:58 am
by carasmo
Thanks! I will.