How to call a item inside a field into another field - YAML TWIG

Hi.

I’m trying to call a item inside a field into another field from Twig template, because I want to filter with expresions “If … Endif” for show or not a content. My blueprint file is this:

'@extends':
type: default
context: blueprints://pages

form:
fields:
    tabs:
        type: tabs
        active: 1
        fields:
            bootstrap-blog:
                type: tab
                title: BOOTSTRAP_BLOG.ADMIN.MODULAR.INTERES
                fields:
                                                                     
                   
                    header.cards:
                        type: list
                        style: vertical
                        label: BOOTSTRAP_BLOG.ADMIN.ITEM.INTERES
                        help: BOOTSTRAP_BLOG.ADMIN.ITEM.INTERES_HELP
                        collapsed: true
                        fields:
                            .icon:
                                type: pagemediaselect
                                label: BOOTSTRAP_BLOG.ADMIN.INTERES_ICON
                            .ruta:
                                type: text
                                label: BOOTSTRAP_BLOG.ADMIN.INTERES_LINK
                                help: BOOTSTRAP_BLOG.ADMIN.INTERES_LINK_HELP
                            .text:
                                type: text
                                label: BOOTSTRAP_BLOG.ADMIN.INTERES_TEXT
                            .description:
                                type: text
                                label: BOOTSTRAP_BLOG.ADMIN.INTERES_DESCRIPTION
                            .url_video:
                                type: link
                                label: BOOTSTRAP_BLOG.ADMIN.VIDEOS_INTERES_URL
                            .url_text_video:
                                type: text
                                label: BOOTSTRAP_BLOG.ADMIN.VIDEOS_INTERES_URL_TEXT
                            .description_video:
                                type: text
                                label: BOOTSTRAP_BLOG.ADMIN.VIDEOS_INTERES_DESCRIPTION

And the code fragment where I want to call that field is this:

{% for card in page.header.cards %}
                        <p class="card-text"><img src="{{page.media[card.icon].url}}"><strong>
                        
                        <a href="{{ card.ruta }}" class="text-primary" target="_blank"> {{card.text}}</a></strong><br>{{card.description}}</p>
                    

                        {% if page.header.cards.url_video %}
                                <div class="col-md-8 col-sm-12 col-12">
                                    <div class="embed-responsive embed-responsive-16by9">
                                        <iframe src="{{card.url_video}}" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
                                    </div>
                                </div>
                                {% if page.header.cards.description_video %}
                                    <p class="card-text"><strong>{{card.description_video}} <a href="{{card.url_video}}" class="text-primary" target="_blank">{{card.url_text_video}}</a>) </strong></p>
                                {% endif %}
                            
                        {% endif %}
                    {% endfor %}

At the moment I could not get to call that item from the twig template. The item is url_video.

I hope you can help me. Thank you

@pmoreno,

First, the answer:

After cutting down to the bare essentials, you have the following template:

{% for card in page.header.cards %}
   ...
   {% if page.header.cards.url_video %}  <-- Not getting right value
      ...
      {% if page.header.cards.description_video %} <-- Not getting right value
        ...
      {% endif %}
   {% endif %}
{% endfor %}

and the following frontmater:

---
cards:
  -
    ruta: 'a link'
    text: 'some text'
    description: 'a description'
    url_video: url-to-video
    url_text_video: video-url-text
    description_video: video-description
---

Inside your template you ‘loop’ over the array of cards available in the frontmatter. To access the value of a single card, you should use card.url_video not page.header.cards.url_video.

Second, a kind request: Please help the reader help you…

You could help the reader by:

  • Using a meaningful title.
    E.g.: “In Twig, I don’t get proper value of frontmatter”
  • Using a clear and concise description.
    E.g. “The variable ‘xyz’ in the following Twig snippet does not seem to return the correct value. The frontmatter is defined as follows …”
  • Showing only relevant data:
    • The blueprint has no relevance to the issue, only the frontmatter does.
    • Cut down code snippets to the essential part.
    • Indicate where to problem seems to occur.
  • Format snippets correctly
4 Likes

First of all, thank you very much for your help. And secondly, I am starting to use this forum and I totally agree with your opinions about my post.
I hope next time I will do better.
Again, thank you so much.