1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Using extra field for uploading image

Discussion in 'Templates, HTML, CSS, and Design Help' started by jason1971, Apr 20, 2014.

  1. jason1971 Customer

    Hi,

    I have a feeling I know what the answer will be, but I will ask it anyways...

    I am using one of the extra fields as a file upload for my advertisers to upload star ratings of their properties using either GIF,JPG,JPEG,BMP,PNG etc.. extentions however when I add the {get_extra_field id=$view fid=45} to viewlisting.tpl the uploaded image does not show up.

    Does this upload extra field not allow image uploads ? if not, is there a way around this ?

    Cheers

    Jason. PS: Happy Easter from the UK
  2. Mike-N-Tosh Owner

    You probably do know the answer. A file upload extra field is designed to be able to upload a downloadable file, therefore the result in the template to get this field will be a clickable download link.

    My suggestion to you would be to use a drop down menu text field and input the ratings that you allow. (e.g. 1, 2, 3, 4, 5) Create corresponding images to display. Then use smarty in the template to check for the value and display the proper image either using a direct <img> or css using a defined class with a background image. (assuming you create a folder in the root directory called, "ratings" and has images 1.jpg ... 5.jpg)
    example using css:
    {get_extra_field id=$view fid=45 assign="rating"}
    {if $rating}
    <div class="ranking rank_{$rating}">&nbsp;</div>
    {/if}

    In stylesheet:
    div.ranking {width:200px;height:30px;margin:5px;}
    .rank_1 {background: url('ratings/1.jpg')}
    ...
    .rank_5 {background: url('ratings/5.jpg')}

    example for in-template smarty:
    <!-- get the field value and assign it to a variable called "rating" -->
    {get_extra_field id=$view fid=45 assign="rating"}

    <!-- Check if there actually is a rating -->
    {if $rating}
    <div> <!-- start a div to display the image in -->
    {if $rating == 1} <!-- use checks to display the proper image -->
    <img src="ratings/1.jpg">
    {elseif $rating == 2}
    <img src="ratings/2.jpg">
    ...
    {/if}
    </div>
    {/if}

Share This Page