Have you seen our new video tutorials? Check it out!

Markdown Field Type

The markdown field type provides a rich markdown editor input.

Introduction

anomaly.field_type.markdown

The markdown field type provides a markdown flavored text editor input.

Configuration

Below is the full configuration available with defaults values:

"example" => [ "type" => "anomaly.fieldtype.editor", "config" => [ "defaultvalue" => null, "height" => 300 ] ]

Configuration
Key Example Description

default_value

# Example Title

The default value.

height

500

The editor height in pixels.

Usage

This section will show you how to use the field type via API and in the view layer.

Setting Values

You can set the markdown field type value with a string.

$entry->example = $content;

Basic Output

The markdown field type always returns the unparsed storage file content.

$entry->example; // Contents of storage::example/input.md

Presenter Output

This section will show you how to use the decorated value provided by the \Anomaly\MarkdownFieldType\MarkdownFieldTypePresenter class.

MarkdownFieldTypePresenter::path()

The path method returns the prefix hinted path to the storage file.

Returns: string
Example
$decorated->example->path(); // storage::path/example.md
Twig
{{ decorated.example.path() }} // storage::path/example.md

MarkdownFieldTypePresenter::render()

The render method renders the content through the markdown engine.

Returns: string
Example
$decorated->example->render();
Twig
{{ decorated.example.render()|raw }}

MarkdownFieldTypePresenter::parse()

The parse method runs the rendered markdown content through the view engine. This is great for parsing Twig in markdown files.

Returns: string
Arguments
Key Required Type Default Description

$payload

false

array

null

Additional payload data for the view.

Example
$decorated->example->parse(['name' => 'Ryan']);
Twig
{{ decorated.example.parse({'name': 'Ryan'})|raw }}
Parsing content before rendering with markdown

If you need to parse the content of the file before running it through the markdown rendering you can try this:

{{ decorated.example.parse()|markdown|raw }}

MarkdownFieldTypePresenter::content()

The content method returns the raw storage file content.

Returns: string
Example
$decorated->example->content();
Twig
{{ decorated.example.content() }}

MarkdownFieldTypePresenter::excerpt()

The excerpt method returns a limited snippet from the text method while preserving whole words.

Returns: string
Arguments
Key Required Type Default Description

$length

false

integer

100

The length to limit the value by.

$end

false

string

...

The ending for the string only if truncated.

Example
$decorated->example->excerpt();
Twig
{{ decorated.example.excerpt() }}

MarkdownFieldTypePresenter::text()

The text method returns the text-only content from the storage file.

Returns: string
Example
$decorated->example->text();
Twig
{{ decorated.example.text() }}

MarkdownFieldTypePresenter::__toString()

The __toString method is mapped to the render method.

Returns: string
Example
$decorated->example;
Twig
{{ decorated.example|raw }}
Heads Up: The __toString will not properly display exceptions spurring from value content.