Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support nested YAML in media metadata #2966

Open
phmg701 opened this issue Jul 17, 2020 · 2 comments
Open

Support nested YAML in media metadata #2966

phmg701 opened this issue Jul 17, 2020 · 2 comments

Comments

@phmg701
Copy link
Contributor

phmg701 commented Jul 17, 2020

Hello, really nice work with Grav! I chose it on top of many other CMSs because:

  • is lean, fast and DB-less

  • has native multilanguage support troughout the system

  • has modular pages OOB

  • YAML-everything (wow!)

I am trying to build a template/gallery module starting from the Cookbook recipe but when I add, in imageX.meta.yaml the following:

title:
  en: Title
  it: Titolo
description:
  en: Description
  it: Descrizione

Twig engine crashes as, for what I understand from debug bar and Clockwork, multilanguage meta is stored inside an array and Twig/Grav expects a string.

Array(1) object: Grav\Common\Page\Medium\ImageMedium
    object: Grav\Common\Page\Medium\ImageMedium
        *gettersVariable: "items"
        *items: Array(17)
            [...]
            title: Array(2)
                en: "Title"
                it: "Titolo"
            description: Array(2)
                en: "Description"
                it: "Descrizione"

Is there a workaround for supporting multi language metadata for images? It would be a great addition to the already excellent language support in Grav!

Thank you

@rhukster
Copy link
Member

rhukster commented Aug 21, 2020

metadata is expected in a flat array, not a nested data currently.

@rhukster rhukster changed the title Unable to work with multi language metadata Support nested YAML in media metadata Aug 21, 2020
@phmg701
Copy link
Contributor Author

phmg701 commented Aug 21, 2020

Further investigation lead to this conclusion, so I managed to manually recreate the <img> tag without errors:
<img src="{{image.resize(640, 640).url}}"></img>
For multilanguage metadata I played around with bi-dimensional arrays this way (with checks and fallbacks):

{% if config.theme.imagemeta.enabled %}
	{% for mf in config.theme.imagemeta.fields %}
		{% if mf.enabled and (not image.meta[mf.meta_field] is null or not image.meta[mf.meta_field][lang] is null) %}
		<p class="mg-metadata mg-meta-{{mf.meta_field}}">{% if not image.meta[mf.meta_field][lang] is null %}{{image.meta[mf.meta_field][lang]}}{% else %}{{image.meta[mf.meta_field]}}{% endif %}</p>
		{% endif %}
	{% endfor %}
{% endif %}

The next big step is to centralize Images in a folder and work/filter them as a database, even by tag in .meta file. I still have to dig deep into Grav's Flex Objects, it might be an option.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants