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.

File Field Variables EE2- What I miss Hout's File Plugin....

September 29, 2010 11:48pm

Subscribe [2]
  • #1 / Sep 29, 2010 11:48pm

    Tony Krol

    21 posts

    So Mark Hout’s plugin provided some nice flexibility through the use of variable pairs.

    Variable Pairs

    {[custom_field]}…{/[custom_field]} — When used as a pair the contained code will loop, outputting all the uploaded files.
    count — Numeric number of each file
    total_results — Total number of files uploaded to the custom field
    file_name — Filename of the uploaded file.
    file_url — URL to the uploaded file.
    file_thumb_name — Filename of the uploaded thumbnail.
    file_thumb_url — URL to the uploaded thumbnail.

    In particular, is there a way to output the file_url, or file_name of a custom field type of file in EE2?

    Why I ask, is that I’m trying to migrate something to EE2 for a client from something that was written for EE 1.6.9 - using Hout’s file plugin, in conjunction with the Happy Worm Audio Player

    <?php
        // to listen: send pages to index/listen/{entry_id}
        //clean file name of .mp3 and replace underscores with spaces
        function clean_name($name) {
            $bad = array('.mp3', '_');
            $good = array('',' ');
            return str_replace($bad, $good, $name);
        }
    ?>
    
    {if segment_2 == 'listen'}
        {exp:weblog:entries weblog="shop" entry_id="{segment_3}" limit="1"}
    {if:else}
        {exp:weblog:entries weblog="shop" order_by="date" limit="1"}
    {/if}
        [removed]
            var playItem = 0;
            var myPlayList = [
                    {mp3_file backspace="1"}
                        {name: "<?=clean_name('{file_name}')?>", mp3: "{file_url}"},
                    {/mp3_file}
                    
            ];
        [removed]

    In my case, this is where Hout’s plugin was super handy.

    {mp3_file backspace="1"}
    {name: "<?=clean_name('{file_name}')?>", mp3: "{file_url}"},
    {/mp3_file}

    It allowed us to create a page like this:

    So, is there a way to loop the entries using just the file custom field? Output the file name? Or the url?

  • #2 / Sep 30, 2010 10:57pm

    Lisa Wess

    20502 posts

    Hi, Tony,

    Couldn’t you just output your entries, then output just the file field, thus looping through them?

    Just as a note:

    {if segment_2 == 'listen'}
        {exp:weblog:entries weblog="shop" entry_id="{segment_3}" limit="1"}
    {if:else}
        {exp:weblog:entries weblog="shop" order_by="date" limit="1"}

    You can’t break up your weblog entries tag like that.  You have to encapsulate the entire tag pair in the conditional.

  • #3 / Sep 30, 2010 11:37pm

    Tony Krol

    21 posts

    Hmm. So there is a way to loop all files attached to one entry? That is exactly what I was trying to get my head around.

    See, because if you have an “entry” for an album, then multiple tracks for that album, you would have to loop all of the files for that 1 entry.

    Or say for a photographers site, if you had a “shoot” which was one entry, and you wanted to display all image files from that 1 shoot…

    Wouldn’t looping just the file field per entry only display one file from each entry, rather than all the files from one entry?


    I apologize in advance if I’m overlooking something that is very simple, or in the user guide.

    In regards to the way we broke up the tag pair, interestingly enough the page works perfectly without the entire pair within that conditional on the 1.6.9 site.

  • #4 / Oct 01, 2010 3:32pm

    Sue Crocker

    26054 posts

    Hmm. So there is a way to loop all files attached to one entry? That is exactly what I was trying to get my head around.

    It depends on how you are associating the files with the entry. For instance, many community members use something like Matrix to do what you’re needing.

    Does that help?

  • #5 / Oct 05, 2010 1:22am

    Tony Krol

    21 posts

    Sue, thanks for the insight.

    Matrix seems like a great direction. Although for certain instances it also seems like overkill and bloat. I am going to try it and find out…

    I actually posted this topic too soon, without doing a thorough test on the file functionality of EE2. I was under the impression, for some reason, that EE2 supported multiple files per “file field” just as Hout’s plugin did w/ 1.6 (if you were to go into the file upload preferences and choose “allow multiple files”), of course, it doesn’t. It only supports one file per custom field.

    I was just spoiled by the simplicity of Hout’s extension…. Creating multiple custom fields was simply not an option, when their could be 2 files uploaded, or 50 for a particular entry. To create custom fields and template conditionals for all of those instances seemed really messy, not only that, but to extract only certain data such as a file name, there would need to be custom fields for that too, whereas Hout’s extension cleaned file names on output. Perhaps I can create an extension in-between for what I need to use it for :|

    Thanks again for the suggestions!

  • #6 / Oct 05, 2010 10:00am

    Sue Crocker

    26054 posts

    Glad to help. Let us know if/when you decide to roll your own solution. 😊 Don’t hesitate to post again as needed.

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

ExpressionEngine News!

#eecms, #events, #releases