[SOLVED] File not appearing in news detail template

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
Post Reply
chillifish
Forum Members
Forum Members
Posts: 92
Joined: Wed Jul 27, 2011 9:26 am

[SOLVED] File not appearing in news detail template

Post by chillifish »

I've uploaded a file to the news detail template and it's not appearing. I would expect it to appear in the following section of the template:

Code: Select all

{if isset($entry->fields)}
  {foreach from=$entry->fields item='field'}
     <div class="NewsDetailField">
        {if $field->type == 'file'}
	  {* this template assumes that every file uploaded is an image of some sort, because News doesn't distinguish *}
          <img src="{$entry->file_location}/{$field->displayvalue}"/>
        {else}
          {$field->name}:&nbsp;{eval var=$field->displayvalue}
        {/if}
     </div>
  {/foreach}
{/if}
If i put the following code in the template:

Code: Select all

{if $entry->file_location}
	<div id="NewsPostDetailFile">
		<img src="{$entry->file_location}/{$field->displayvalue}" alt="Article image" />
	</div>
{/if}
I get the alt text, but the image location is not completed.
Last edited by chillifish on Thu Oct 16, 2014 10:31 am, edited 1 time in total.
psy
Power Poster
Power Poster
Posts: 463
Joined: Sat Jan 22, 2005 11:19 am

Re: File not appearing in news detail template

Post by psy »

Try {$field->value}
chillifish
Forum Members
Forum Members
Posts: 92
Joined: Wed Jul 27, 2011 9:26 am

Re: File not appearing in news detail template

Post by chillifish »

I'm afraid that doesn't work either. I'm sure it's got something to do with the way I'm referencing the field value object. What concerns me is that the first option which is actually in the sample template doesn't work, which suggests the module is broken.
psy
Power Poster
Power Poster
Posts: 463
Joined: Sat Jan 22, 2005 11:19 am

Re: File not appearing in news detail template

Post by psy »

Are you using the {foreach} loop for the custom fields or accessing them individually?
chillifish
Forum Members
Forum Members
Posts: 92
Joined: Wed Jul 27, 2011 9:26 am

Re: File not appearing in news detail template

Post by chillifish »

Acessing them individually, but the foreach loop doesn't work either as can be seen from the first example.
psy
Power Poster
Power Poster
Posts: 463
Joined: Sat Jan 22, 2005 11:19 am

Re: File not appearing in news detail template

Post by psy »

OK, individuallly.

So does:

Code: Select all

<img src="{$entry->file_location}/{$entry->fields.MYIMAGEFIELDNAME->value}"/>
work?

Does your fieldname have a space in it eg 'My Image'? If so, try:

Code: Select all

{$myimage='My Image'}
<img src="{$entry->file_location}/{$entry->fields.$myimage->value}"/>
Really need more info about the field you are trying to access.
chillifish
Forum Members
Forum Members
Posts: 92
Joined: Wed Jul 27, 2011 9:26 am

Re: File not appearing in news detail template

Post by chillifish »

That doesn't work either.

I have a field with a name of "Image" and a type of "file". In the article, I have browsed for a file and uploaded it. It's on the server when I check with the file browser.

The above News Detail template gives me the location of the enclosing folder, but won't give me the name of the file.
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1974
Joined: Mon Jan 29, 2007 4:47 pm

Re: File not appearing in news detail template

Post by Jo Morg »

In CMSMS version 1.11.11 I just tested and it works for me. Are you sure that the field definition is set to public?
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
chillifish
Forum Members
Forum Members
Posts: 92
Joined: Wed Jul 27, 2011 9:26 am

Re: File not appearing in news detail template

Post by chillifish »

THANKYOU, THANKYOU, THANKYOU.

I hadn't set it to public, DOH.
Post Reply

Return to “The Lounge”