ArchangelX Posted January 12, 2016 Posted January 12, 2016 Hi, I'd like to code a default image in case someone doesn't upload an image. Does anyone know how to add in a Default Image if the member doesn't upload one? I'm using this for a database using custom fields. I assume I'll need to add to this code with an elseif statement since I have more than two images to choose, but I'm not sure how to write a direct url into it? <a href="{$record->url()}" style="background-image: url({{if ($id == 0)}}{file='$record->field_19' extension='cms_Records'}{{else}}{file='$record->record_image_thumb' extension='cms_Records'}{{endif}}); width:100%;"> I've written as such elsewhere but not sure how to add this into that type of coding... <a href="{$record->url()}" title="{lang="read_more_about" sprintf="$record->_title"}"><img class="ipsUserPhoto" src="http://www.xxxx.com/defaultimage.jpg"></a> Can anyone help me write this appropriately?
opentype Posted January 12, 2016 Posted January 12, 2016 It’s not the only way to do it, but I am just pasting my code snippet here where I did exactly what you are asking for. {{if $row->field_52}} <a href='{$row->url()}'><div style='background-image:url({file="$row->field_52" extension="cms_Records"});'></div></a> {{else}} <a href='{$row->url()}'><div style='background-image:url(http://typography.guru/xmodules/assets/noimage.png);'></div></a> {{endif}}
ArchangelX Posted January 12, 2016 Author Posted January 12, 2016 Not sure how to work this into the existing string I'm using but I'll play with it and see if I can get it to work. Thank you so much for the help.
ArchangelX Posted January 12, 2016 Author Posted January 12, 2016 Urgh, I can't get it to work. I tried copying and modifying your string to fit mine, but no jive. Then I tried replacing the code in different ways. I just want to replace field_xx with a direct url in the existing string. Any further ideas? See, it's a little different because it's using a background url that is using an else statement within the code. So it has to work as so.... <a href="{$record->url()}" style="background-image: url({{if ($id == 0)}}{file='$record->field_19' extension='cms_Records'}{{else}}{file='$record->record_image' extension='cms_Records'}{{endif}}); width:100%;"> I want to replace the second bit after the else statement.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.