Page 1 of 1
get image url from file upload field in news
Posted: Thu Aug 02, 2012 12:35 pm
by piphansdk
Hello.
I am trying to make a code in my summary template wich shows a picture of the uploaded file.
and if the field is empty, a no_image.png.
i just need the last things in my code

thanks for any help
Code: Select all
{if $entry->image}
<img src="{no idea}" align="left" height="270px" width="302px"/>
{else}
<img src="uploads/images/news.png" alt="news" align="left" height="270px" width="302px" />
{/if}
as you maby see, i need the file location acording to the news article. I found out that the uploaded images is located in: uploads/images/news/"{newsid}"/filename.extension
Re: get image url from file upload field in news
Posted: Thu Aug 02, 2012 3:21 pm
by uniqu3
Look in Sample News Templates, you will find {$entry->file_location} which gives full path to your file.
Re: get image url from file upload field in news
Posted: Sat Aug 04, 2012 3:52 pm
by piphansdk
hi.
sorry i'm a bit lost

could you please write, the line with the {entry}, it all please, and how does i know witch field it is?
Re: get image url from file upload field in news
Posted: Sat Aug 04, 2012 3:59 pm
by piphansdk
ohh... think i found out... with another forum

but how to tell it if entry?
and is this good?
<img src="{$entry->file_location}/{$entry->fields.Foto->value}" alt="{$entry->product_name}" />
Re: get image url from file upload field in news
Posted: Sat Aug 04, 2012 5:22 pm
by carasmo
Code: Select all
{if $entry->fieldsbyname.image != ''}
<img src="{$entry->file_location}/{$entry->fieldsbyname.image->value}" alt="{$entry->title|cms_escape:html}" />
{/if}
I don't use regular image tags, just CGSmartImage, so this is a rough idea minus the width and height tags and the class or the wrapper where the image goes you may or may not want to add inside the if statements.
There might be shorter ways, perhaps:
Code: Select all
{if $entry->fieldsbyname.image->value}
<img src="{$entry->file_location}/{$entry->fieldsbyname.image->value}" alt="{$entry->title|cms_escape:html}" />
{/if}
So yours would kinda look like the information below. Please play around to see what works for you.
Code: Select all
{if $entry->fieldsbyname.image->value}
<img src="{$entry->file_location}/{$entry->fieldsbyname.image->value}" align="left" height="270px" width="302px"/>
{else}
<img src="uploads/images/news.png" alt="news" align="left" height="270px" width="302px" />
{/if}
Re: get image url from file upload field in news
Posted: Fri Aug 10, 2012 8:28 pm
by piphansdk
Hi!
Thanks for any reply!
I just can't make I work

is it because of the foreach?
I will post my code and hope to get help
Code: Select all
<__script__ src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></__script>
<__script__ src="modules/NewsSlides/Linking/js/slides.min.jquery.js"></__script>
<__script__>
{literal}
$(function(){
// Set starting slide to 1
var startSlide = 1;
// Get slide number if it exists
if (window.location.hash) {
startSlide = window.location.hash.replace('#','');
}
// Initialize Slides
$('#slides').slides({
preload: true,
preloadImage: 'modules/NewsSlides/Linking/img/loading.gif',
generatePagination: true,
play: 10000,
pause: 100,
hoverPause: true,
// Get the starting slide
start: startSlide,
animationComplete: function(current){
}
});
});
{/literal}
</__script>
<div id="container">
<div id="example">
<div id="slides">
<div class="slides_container">
{foreach from=$items item=entry}
<div class="slide">
{if $entry->fieldsbyname.image->value}
<img src="{$entry->file_location}/{$entry->fieldsbyname.image->value}" align="left" height="270px" width="302px"/>
{else}
<img src="uploads/images/news.png" alt="news" align="left" height="270px" width="302px" />
{/if}
<img src="uploads/images/line.gif" alt="line" align="left" height="270px" style="padding:0px 10px 0px 5px;" />
{if $entry->postdate}
<div class="NewsSummaryPostdate">
{$entry->postdate|cms_date_format}
</div>
{/if}
<div class="NewsSummaryLink">
<a href="{$entry->moreurl}" title="{$entry->title|cms_escape:htmlall}">{$entry->title|cms_escape}</a>
</div>
<div class="NewsSummaryCategory">
{$category_label} {$entry->category}
</div>
{if $entry->author}
<div class="NewsSummaryAuthor">
{$author_label} {$entry->author}
</div>
{/if}
{if $entry->summary}
<div class="NewsSummarySummary">
{eval var=$entry->summary}
</div>
<div class="NewsSummaryMorelink">
[{$entry->morelink}]
</div>
{else if $entry->content}
<div class="NewsSummaryContent">
{eval var=$entry->content}
</div>
{/if}
{if isset($entry->extra)}
<div class="NewsSummaryExtra">
{eval var=$entry->extra}
{* {cms_module module='Uploads' mode='simpleurl' upload_id=$entry->extravalue} *}
</div>
{/if}
{if isset($entry->fields)}
{foreach from=$entry->fields item='field'}
<div class="NewsSummaryField">
{if $field->type == 'file'}
<img src="{$entry->file_location}/{$field->value}"/ 1>
{else}
{$field->name}: {eval var=$field->value}
{/if}
</div>
{/foreach}
{/if}
</div>
{/foreach}
<!-- End News Display Template -->
</div>
Re: get image url from file upload field in news
Posted: Fri Aug 10, 2012 9:03 pm
by carasmo
Loading scripts in the body of the page is wrong. In your Page Template (not news template) you can load specific code and css for the slider in the
head of the html. Place the page alias of the page where the slider appears. This is one way of doing it.
Code: Select all
{if $page_alias eq 'page-alias-here'}
{*scripts go here*}
{/if}
Then troubleshoot your issue by detaching the script. That is change the name of the class on the html, turn off javascript, create a duplicate news template without the script, there's a variety of ways.
Check your error logs in firebug, etc.,
Try to load the page w/o the script, if it works, then it's the script. Try to get help from the script forum. Make the most vanilla version of your news template and get it to work before anything added, then you will know what messed it up. Check your CSS and html too everywhere on the page to make sure you've closed everything, missing html or just a closing quote mark on a url will mess up a page.