General discussions about WebYep
-
filzfun
- Posts: 8
- Joined: Thu Jul 24, 2008 4:45 am
- Location: Washington DC
Post
by filzfun » Sat Aug 30, 2008 10:54 pm
I'd like to add an icon to the left of an attachment but make sure there is no icon when no attachment is present. Has anyone tried to do this?
If I code this way, I have an icon on my page even if no attachment has been uploaded:
Code: Select all
<img src="/images/elements/icons/pdficon_small.gif"><?php webyep_attachment("attachment"); ?>
What I'd like to do is something like this:
Code: Select all
<?php
$var = webyep_attachment("attachment");
if (empty($var)) {
echo "<img src='/images/elements/icons/pdficon_small.gif'>" . $var;
}
?>
but that doesn't work. Any suggestions?
-
johannes
- Objective Development

- Posts: 815
- Joined: Fri Nov 10, 2006 4:39 pm
-
Contact:
Post
by johannes » Mon Sep 01, 2008 7:08 am
The webyep_attachment() function call has no return value - it directly ouputs the HTML code.
You would have to use somehting like this:
Code: Select all
<?php $o =& new WYAttachmentElement("attachment", false);
if ($o->sDisplay() != "") { ?>
Attachment present!
<?php } ?>
But one of the next releases of WebYep will include an enhanced Attachment Element, that will offer a configurable download icon.
-
filzfun
- Posts: 8
- Joined: Thu Jul 24, 2008 4:45 am
- Location: Washington DC
Post
by filzfun » Wed Sep 10, 2008 7:58 pm
Thank you, Johannes. Awesome as always.
For the record, this is how my code now looks. The pdf icon for the attachment appears to the left of the attachment link and only when said attachment exists.
Code: Select all
<?php webyep_shortText("attachment-description", false); ?>
<?php $o =& new WYAttachmentElement("attachment", false);
if ($o->sDisplay() != "") { ?>
<img src="/images/icons/pdficon_small.gif">
<?php } ?>
<?php webyep_attachment("attachment");?>
-
johannes
- Objective Development

- Posts: 815
- Joined: Fri Nov 10, 2006 4:39 pm
-
Contact:
Post
by johannes » Wed Sep 10, 2008 8:04 pm
Thank you for contributing your code!
The icon won't serve as a download link - that's what the new Attachment Element (we're targeting 1.3.1) will do. But until then, your code is a valuable substitution!
-
johannes
- Objective Development

- Posts: 815
- Joined: Fri Nov 10, 2006 4:39 pm
-
Contact:
Post
by johannes » Fri Feb 13, 2009 4:44 pm
The current version of WebYep (1.4.0) lets you define your own download icon.
Currently this can only be done when adding the Attachment Element's PHP code by hand. The new signature of the Attachment Element's PHP function is:
webyep_attachment($sFieldName, $bGlobal = false, $sCustomIcon = "")
so a new parameter for the URL of the custom icon was added - e.g.:
<?php webyep_attachment("Resume", false, "/images/download.gif") ?>
-
Dave Camenisch
- Posts: 1
- Joined: Wed Aug 20, 2014 10:12 am
Post
by Dave Camenisch » Wed Aug 20, 2014 10:33 am
Attention:
If you are using PHP5, you have to remove the "&" ($o = new WYAttachmentElement...).
Just in case you are using the syntax from above.
-- Dave