Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Support

Need help with display selected option key

Solved by Pedro M View solution

Started by Natalia Bazilenco 3 years ago · 2 replies · 259 views
3 years ago

Hi friends, I'm making a modular page on the site to display social networks.
I created the social.yaml with next code:

YAML
title: Social links
'@extends': default

form:
  fields:
    tabs:
      fields:
        content:
          fields: 
            header.social_media:  
              name: features
              type: list
              label: My socila links
              fields:
                .title:
                  type: select
                  label: Name of network
                  default: one
                  options:
                    one: Facebook
                    two: Instagram
                    three: Telegram
                  use: keys
                .text:
                  type: text
                  label: Link to network
                  fields:
                .design:
                  type: select
                  label: Icon design 
                  default: Original
                  options:
                    one: Original
                    two: Custom

As planned, I want to output like this final code:

HTML
<ul class="social_media">
<li class="facebook"><a href="#"><i class="fa facebook"></i></a></li>
<li class="instagram"><a href="#"><i class="fa instagram"></i></a></li>
</ul>

In social.html.twig added this, but can display in class="the name of selected options"

TWIG
{% for header in page.header.social_media %}
   <ul class="socail_media">
 <li><a href="{{ header.text }}"><i class="fa  key/value of select option "></i></a></li>
 <li><a href="{{ header.text }}"><i class="fa  key/value of select option "></i></a></li>
   </ul>
{% endfor %}

Any ideas, please.

3 years ago Solution

You could the following:

In social.yaml:

YAML
header.social_media:  
    name: social
    type: list
    label: My socila links
    fields:
      .title:
        type: select
        label: Name of network
        default: Facebook
        options:
          Facebook: 'Facebook'
          Instragram: 'Instagram'
          Telegram: 'Telegram'
      .link:
        type: text
        label: Link to network
      .icon:
        type: iconpicker
        label: Icon
      .icon_design:
        type: select
        label: Icon design 
        default: regular
        options:
          regular: Regular
          solid: Solid

In social.html.twig:

TWIG
<ul class="social_media">
    {% for item in page.header.social_media %}
    <li>
        <a href="{{ item.link }}">
            <i class="{{item.icon}} {{item.icon_design}}"></i>
            {{item.title}}
        </a>
    </li>
    {% endfor %}
</ul>
👍 1

Suggested topics

Topic Participants Replies Views Activity
Support · by Thomas, 1 week ago
2 52 9 hours ago
Support · by Anna, 3 days ago
2 59 11 hours ago
Support · by Justin Young, 12 hours ago
1 30 12 hours ago
Support · by Duc , 1 week ago
2 65 5 days ago
Support · by Colin Hume, 1 week ago
2 56 5 days ago