Includes

Includes let you bring in arbitrary HTML from your Includes directory.

For example, the HTML below was imported from Includes/important.html

Include("important.html")

This is an included file.

Loading arbitrary data

If you want to load arbitrary resources for parsing in your Swift code, you should create a folder called Resources then you have three options.

First, context.url(forResource:) tells you the full path to a file in Resources.

Second, context.data(forResource:) locates a file in Resources and loads it into a Data instance. This uses context.url(forResource:) internally.

And third, context.decode(resource:as:) locates a JSON file, loads it into a Data instance, then decodes it to a Decodable type of your choosing. This uses context.data(forResource:) internally, which in turn uses context.url(forResource:).

For example, this project contains some JSON in Resources/quotes.json, so we can display its contents using the below:

if let quotes = context.decode(resource: "quotes.json", as: [String].self) {
    for quote in quotes {
        Quote {
            quote
        }
    }
}
The only limit to our realization of tomorrow will be our doubts of today.
It is never too late to be what you might have been.
You must be the change you wish to see in the world.

Tip: This page uses a custom theme, which is dark

Created with Ignite