ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Link to file or URL

September 15, 2011 12:01pm

Subscribe [3]
  • #1 / Sep 15, 2011 12:01pm

    tomjeatt

    19 posts

    I’ve been asked to create a channel to link to reports which will either be a local file or an external URL.

    I can see an easy way to achieve this - add two non mandatory fields, one for the URL and one for the file, and use an if/else statement in the template to populate the href attribute of the anchor tag.

    The problem is that this is less than bulletproof - someone could fill out both fields which would cause a few problems, or become a little confused about what is required. Or they could just add the title and link to nothing, since that would be the only required field.

    What I’d like to do is have a dropdown which requires content editors to choose whether they’re linking to a file or a URL. Both the URL field and the file upload field will be disabled initially, but the relevant field will become active and mandatory depending on which of the options has been selected.

    Is this possible?

  • #2 / Sep 15, 2011 2:46pm

    Mark Bowen

    12637 posts

    Hi tomjeatt,

    There are no drop-down fields for ExpressionEngine that do what you’re after here directly built into ExpressionEngine and I’m not sure if any 3rd party add-ons exist for this type of thing either.

    What you could do here though is have your two fields, one for the URL and one for the file and then have a drop-down which has the options of :


    File
    URL

    Place the one you think is more likely to get used at the top.

    Then in your template you could do this :

    {exp:channel:entries
        channel="default_site"
        disable="member_data|trackbacks|categories|category_fields|pagination"}
    
    {if drop_down_field == "File"}
    <a href="http://{file}" title="{title}">{title}</a>
    {if:else}
    <a href="http://{file_url}" title="{title}">{title}</a>
    {/if}
    
    {/exp:channel:entries}

    Fields Used
    drop_down_field - Self explanatory 😉
    file - Holds your file.
    file_url - Holds a URL to a file.

    This would mean that whoever enters the content would need to make sure that they choose the correct option from the drop-down. That would at least stop the problems if they fill in both fields.

    Don’t know if that helps at all though?

    Best wishes,

    Mark

  • #3 / Sep 15, 2011 3:08pm

    tomjeatt

    19 posts

    Hi Mark

    Yes it does, thanks! Not perfect, but removes one layer of ambiguity and means that the user has to think about what they’re doing. It will also easier for them to see what’s gone wrong if it’s not working as it should. I’ll add an explanatory note to the drop down field and then I think I’ve probably done enough.

    Thank you!

  • #4 / Sep 15, 2011 6:37pm

    Mark Bowen

    12637 posts

    Hi Tom,

    No problem at all. Glad that helped a bit.

    Best wishes,

    Mark

  • #5 / Sep 16, 2011 7:04pm

    John St-Amand

    865 posts

    The “entry type” add-on from Rob Sanchez would help you do this in the CP.  It’s a drop-down that conditionally hides other fields in your field group based on which item in the drop down is selected.  That way when they choose the type, the field(s) no longer relevant is removed.

  • #6 / Sep 16, 2011 7:40pm

    Mark Bowen

    12637 posts

    Yep I remember that add-on. Had a few problems with it when it first came out although to tell the truth I can’t for the life of me remember what they were now.

    Definitely a great idea that one though.

  • #7 / Sep 19, 2011 5:07am

    tomjeatt

    19 posts

    The “entry type” add-on from Rob Sanchez would help you do this in the CP.  It’s a drop-down that conditionally hides other fields in your field group based on which item in the drop down is selected.  That way when they choose the type, the field(s) no longer relevant is removed.

    Thank you - I’ll download it and give it a go. I’ll let you know if any of those problems have been ironed out.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases