[SalesForce] Reference Static Resource in Zip File

I've been doing this:

{!URLFOR($Resource.file,'0.jpg')}

to reference from a visual force page a static resource inside a zip file, there are some files 0.jpg, 1.jpg, etc. at the top level of the zip file but is beyond me why is not working (by this I mean, the image is not showing in the page). If someone can enlighten me about it, I would appreciate.

Update

I have a page construct as this:

<apex:page standardController="Contact" docType="html-5.0" standardStylesheets="false" cache="true" applyBodyTag="false" recordSetVar="contacts" extensions="Some_Ext">
    <head>
        <apex:styleSheet value="{!$Resource.style}"/>
    </head>
    <body>
        <apex:form>
            <apex:image value="{!URLFOR($Resource.resourcename, '0.jpg')}"/>
        </apex:form>
    </body>
</apex:page>

Note

The problem was that the image was a .png not a .jpg as I was referencing in the VF Page.

¡Be completely sure of the path and file EXTENSION when referencing a Static Resource!

Best Answer

Check this documentation

https://www.salesforce.com/us/developer/docs/pages/Content/pages_resources_reference.htm

To reference a file in an archive, use the URLFOR function. Specify the static resource name that you provided when you uploaded the archive with the first parameter, and the path to the desired file within the archive with the second. For example:

 url="{!URLFOR($Resource.TestZip,
                  'images/Bluehills.jpg')}" width="50" height="50"/>

(OR) if 1 is too confusing save the CSS/ JS/ Image or be it anything as a seperate static resource and reference it in VF page as

URLFOR($Resource.file_image)
URLFOR($Resource.file_CSS)
URLFOR($Resource.file_image)

I usually prefer the second method since I have never been comfortable with zip file and extending the path.

Update:

My ZIP file content:

enter image description here

The page saves even though u do not have the closing } bracket, check if you have formed the image tag and closed the { and } for the URLFOR function.

Make sure the syntax is correct for the image tag as well as the URLFOR.

enter image description here

<apex:page >
<apex:form >
<apex:image value="{!URLFOR($Resource.tezip, 'te.jpg')}" />
</apex:form>
</apex:page>

My output was :

![enter image description here][3]


UPDATE 2:

YOUR CODE IN MY ORG :D:


enter image description here

Related Topic