6 users online. Create an account or sign in to join them.Users
How to test if entry contains an image?
This is an open discussion with 14 replies, filed under Troubleshooting.
Search
Is the XML showing an empty <image/> element? If so then the test above will not work. The alternative is to make sure there’s nothing inside the image element:
<xsl:if test="image/filename">
I often use <xsl:if test="image/*"></xsl:if> to check if the node is not empty.
Hey,
Thanks for your help.
It’s strange though, both your suggestions don’t work.
This is what an entry looks like that really contains an image:
<image size="24 KB" path="/images/projects" type="image/jpeg">
<filename>photo.jpg</filename>
<meta creation="2010-08-22T21:40:10+02:00" width="250" height="180" />
</image>
And this is an entry that does not contain any image:
<image size="4 KB" path="/www/htdocs/w009f44g/taas.designbits.de" type="">
<filename />
</image>
Really strange, isn’t it?
taas.designbits.de is the subdomain I am currently working on.
Your second example should never happen, so this looks like a Symphony bug. If an image doesn’t exist then the File Upload field should not output an element. Can you confirm which version of Symphony you’re using?
I can confirm this bug. It happened to me as well lately. The size was 4 KB, the path was the absolute path on my server and my filename was an empty tag.
It was with Symphony 2.1.0
The workaround I used (which worked) was:
<xsl:if test="data/content/entry/picture/filename != ''">
(do some stuff here)
</xsl:if>
Didn’t actually occure to me then that this could be a bug.
Hey Nick,
I am using version 2.1.0.
It’s funny because I am using the exact same code in a version 2.0.7 project and it works like a charm there.
Any ideas how to fix it in 2.1.0?
Hey Kanduvisla,
Sorry, saw your post too late.
The workaround looks ugly though :-(
Would be nice to get this fixed…
Issue #375: Empty File Upload Showing in XML needs to be re-opened it seems.
I am using version 2.1.0.
Ah I think this was fixed in 2.1.1 with these lines:
OK, so what’s the best way for me to fix it in version 2.1.0?
Would you suggest to simply replace field.upload.php with the one from 2.1.1?
My choice would be update fully to 2.1.1 (take a copy of your site and database first as a backup, then update). But if you don’t have the time/inclination then you should be able to replace the file. Or you could simply add those new lines.
OK, I simply added those new lines and it works again now.
Couldn’t bother to upgrade the entire installation ;-)
Thanks for your help, guys.
Actually, Symphony is one of the few open source solutions I trust to perform an update. Always when I have to make some modifications to a site later on and there is a new version of Symphony, I always update.
But whatever you are updating, if it is a website or a complete computer, making a backup is always the first thing to do! ;-)
As it’s only a minor release, there are only bug fixes in place, so any code used with 2.1.0 will be fully compatiable with 2.1.1, but yes, back up.
The only files/folder you will need to replace are:
/symphony /index.php /update.php
Then run update.php, really simple.
Create an account or sign in to comment.
Hello,
I have this code on my website:
<xsl:template match="projects/entry"> <xsl:value-of select="titel"/> <xsl:if test="image"> <img src="{$workspace}/images/projects/{image/filename}" /> </xsl:if> </xsl:template>However, for some reason, when a project does not contain an image, Symphony tries to display it anyway and I get an ugly question mark in my browser. What I really want is nothing though.
I really can’t get my head around this. I am using the exact same code in another project and it works great.
Can anybody tell me what I’m missing here?
Thanks for any help.