Skip to content
● Meet Grav Guard: keep every Grav site you run secure and up to date, all from one place. Free for up to 3 sites. Read more →

Textarea editor called in YAML not processing markdown

Solved by hughbris View solution

Started by Pedro Oliveira 9 years ago · 3 replies · 1650 views
9 years ago

Hi,

Created a template and respective yaml:

YAML
title: Text
'@extends': default

form:
  fields:
    tabs:
      fields:
        content:
          fields:
            header.media_order:
              label: Page Media (first one will be displayed next to your content)
            header.image_align:
              type: select
              label: Image position
              classes: fancy
              default: left
              options:
                'left': 'Left'
                'right': 'Right'
        features:
          type: tab
          title: '+ Info'
          fields:
              header.extra_info:
                type: editor
                validate:
                    type: textarea
                label: Info Adicional
                markdown: true

.. and called it in twig file: {{ header.extra_info }}

For some reason markdown isn't being processed.
Am I missing something?

Cheers!
Pedro

9 years ago Solution

Educated guess here ...

I don't think the markdown property here is doing anything except ensuring that when the page is edited or created, its extra_info field is saved as YAML-compatible markdown.

However, I can't see any docs on this markdown property - where did you find out about it? The editor field type supports markdown natively I thought.

Anyway ... when the template comes to use it, it's not consulting the blueprint to see what type the field should be. Try applying a filter in your template like:

{{ header.extra_info|markdown }}

and the markdown should be processed. I am pretty sure templates are not blueprint-aware.

9 years ago

You are totally right. After adding |markdown to twig, it worked as expected. As for markdown property, I think it was somewhere in admin plugin, but I'll have to confirm.

Thank you,
Pedro

9 years ago

It's probably good that Twig is ignorant by default of blueprints and form field types:

  • template designers should be considering this anyway and it makes the templates more self-documenting
  • it provides more flexibility.

Having said that, I hacked the data manager plugin recently to enable specifying output formats for fields and I'm thinking of adding my change as a pull request. My use case was formatting a datetime field that I wanted to store as UTC, which is obviously not very readable.

Cheers

Suggested topics

Topic Participants Replies Views Activity
Forms & Blueprints · by Anna, 2 days ago
2 53 16 hours ago
Forms & Blueprints · by Anna, 3 days ago
7 82 16 hours ago
Forms & Blueprints · by Anna, 1 week ago
5 186 6 days ago
Forms & Blueprints · by TomW, 1 month ago
3 379 1 month ago
Forms & Blueprints · by Japhy, 2 months ago
2 595 2 months ago