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 }}
The __toString will not properly display exceptions spurring from value content.{.note}