Jump to content

Direct URL images in code not being shown


ArchangelX

Recommended Posts

Posted

I'm trying to setup a default image when one hasn't been uploaded.

When I place it within the else statement it doesn't work:

      <section class='ipsType_normal ipsType_richText ipsType_break ipsSpacer_both' data-ipsTruncate data-ipsTruncate-size='7 lines' data-ipsTruncate-type='remove'>
{{if $record->customFieldDisplayByKey('upload_images', 'display')}}
        <div class="cCmsRecord_image">
          <div class="ipsUserPhoto ipsUserPhoto_large">{$record->customFieldDisplayByKey('upload_images', 'display')|raw}</div>
        </div>
   {{else}}
      <div class="cCmsRecord_image">
        <img class="ipsUserPhoto ipsUserPhoto_large" src="http://www.####.com/img/sshdefault.jpg
      </div>
      {{endif}}

But if I place it outside of the else statement, it works fine.  If I replace the src file with the standard image code key, it works fine but I want to show the default image if noone uploads an image file.  This is key to maintaining the look of the grid.

Is this related to this issue?

https://community.invisionpower.com/topic/418451-insert-image-from-a-url-not-working/

Thanks.

Posted

It is unrelated to that issue. That if check will not work unfortunately, even if no value is provided, that method call is not returning a blank string.

Similar methodology to the above is needed to actually properly have that if work:

{{$FieldsClass  = '\\IPS\\cms\\Fields'  . \IPS\cms\Databases\Dispatcher::i()->databaseId;}}
{{$fieldsByKey = array();}}
{{foreach $FieldsClass::data('view', $record->container(), $FieldsClass::FIELD_SKIP_TITLE_CONTENT) as $field}}
{{$fieldsByKey[$field->key] = 'field_' . $field->id;}}
{{endforeach}}
{{if $record->$fieldsByKey['upload_images']}}
<!--field has value-->
{{else}}
<!--field is empty-->
{{endif}}

 

Posted

Hi Marcher Tech,

Thank you for your help. I modified it as you provided and it didn't work.  Am I doing something wrong?

<section class='ipsType_normal ipsType_richText ipsType_break ipsSpacer_both' data-ipsTruncate data-ipsTruncate-size='7 lines' data-ipsTruncate-type='remove'>
{{$FieldsClass  = '\\IPS\\cms\\Fields'  . \IPS\cms\Databases\Dispatcher::i()->databaseId;}}
{{$fieldsByKey = array();}}
{{foreach $FieldsClass::data('view', $record->container(), $FieldsClass::FIELD_SKIP_TITLE_CONTENT) as $field}}
{{$fieldsByKey[$field->key] = 'field_' . $field->id;}}
{{endforeach}}
{{if $record->$fieldsByKey['upload_images']}}
	<div class="cCmsRecord_image">
        <div class="ipsUserPhoto ipsUserPhoto_large">{$record->customFieldDisplayByKey('upload_images', 'display')|raw}</div>
    </div>
{{else}}
    <div class="cCmsRecord_image">
        <img class="ipsUserPhoto ipsUserPhoto_large" src="http://www.stolenstuffhawaii.com/uploads/sshdefault.jpg">
    </div>
{{endif}}

 

Posted

Not that I am aware of. Something more is going on there. Is the field default configured to be something not a blank string? if not, what is the value produced for records with no image uploaded for that field when you do a:

{expression="var_export($record->$fieldsByKey['upload_images'], true)"}

 

Posted

Shoots! I was looking at the wrong page, it works!  Thanks so much Marcher!  I'm going to look at your code and try and understand how it all works. Thanks so much for your help.

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...