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 →

Parse YAML & content out of a string/file

Erin Dalzell December 18, 2014 by Erin Dalzell

Let's say I have a string:

title: test-me
  - ""
tags: ""
author: erin

more stuff here

I'd like to parse it into YAML and content. What calls would I use??

YAML::parse is only expecting YAML, so gives funny results for the content part. I took a quick look through the source but couldn't figure how Statamic is parsing the files (not sure what to search for to find it).

Ideas? Suggestions?

Edit: found the parsing code but I'd rather not duplicate. Is it exposed anywhere as a function??

                $content       = substr(File::get($file), 3);
                $divide        = strpos($content, "\n---");
                $front_matter  = trim(substr($content, 0, $divide));
                $content_raw   = trim(substr($content, $divide + 4));

                // parse data
                $data = YAML::parse($front_matter);
>>>>>>> Unanswered <<<<<<<
1 Reply
1 Follower