We've retired the forum in favor of GitHub Discussions.

New conversations can be started on GitHub. Existing conversations will remain for a while longer.

Head over to GitHub →

Function to return proper file prefix for entries

Erin Dalzell January 3, 2015 by Erin Dalzell

It would be nice if there was a Statamic function (maybe in File?) to return the proper prefix for a folder (data/number). Code would be:

        // create the appropriate prefix
        $entry_type = Statamic::get_entry_type($folder);

        $order_prefix = "";
        if ($entry_type == 'date') {
            if (Config::get('_entry_timestamps')) {
                $order_prefix = date('Y-m-d-Hi-');
            }
            else {
                $order_prefix = date('Y-m-d-');
            }
        } else if ($entry_type == 'number') {
            $order_prefix = Statamic::get_next_numeric($folder) . "-";
        }

Edit: would be even better that from a folder, a title and a status, it create the full filename and/or full path. (i.e add in:

        // the slug comes from the title in lowercase with '-' as a delimiter
        $slug = Slug::make($entry->title, array('lowercase' => true));

        // get the status prefix from the post status
        $status_prefix = Slug::getStatusPrefix($entry->post_status);

        // make the file name
        $filename = $status_prefix . $order_prefix . $slug;

        $fullpath = Path::assemble(BASE_PATH, Config::getContentRoot(), Path::resolve($folder . DIRECTORY_SEPARATOR . $filename) . '.' . Config::getContentType());
>>>>>>> Unanswered <<<<<<<
2 Replies
2 Followers