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.

Themes & Styling

Receptar Skeleton Home page with 2 languages Slider, is it possible? how?

Solved by Jose View solution

Started by Jose 2 years ago · 9 replies · 117 views
2 years ago

Hello,

  1. In Receptar GitHub pages, in Features, it says:

Basic translations for 14 languages

https://github.com/getgrav/grav-skeleton-receptar-site

  1. I know the Slider is handled on the site.yaml file, not via the Admin Module:
    YAML
    
    slider:
    - image: slide3.jpg
    title: A very delicious blog
    url: "#"
    - image: slide1.jpg
    title: Duis autem
    url: "#"
    - image: slide2.jpg
    title: Pumpkin recipe
    url: "#"
    
TXT

I have no problem with translating the pages; Grav documentation helps a lot, but I do not know how to translate the title of each image slide into the second language; only two languages are needed.

Thanks in advance for any Ideas on resolving this slider's multi-language title.
Regards
joejac
2 years ago

Placing slider data in the site.md file is not a very flexible solution. In my opinion, you should:

  1. Create a directory called pages/slider.
  2. Inside the pages/slider directory, create subdirectories for each slide, e.g., pages/slider/01._slide-1, pages/slider/02._slide-2.
  3. Inside each subdirectory, create files with data for each language, e.g., default.md and default.pl.md.
  4. In each of the files, include the data. For example, in default.md:
YAML
---
title: Title EN
image: slide1.jpg
url: #
---

And in default.pl.md:

YAML
---
title: Tytuł PL
image: slide1.jpg
url: #
---
  1. Modify the file 'pages/01.blog/blog.md' and add:
YAML
slider:
    items:
      '@page.modules': '/slider'
  1. Modify the file: user/themes/receptar/templates/partials/slider.html.twig, for example:
PHP
<div id="site-banner" class="site-banner enable-slider">
  <div class="site-banner-inner">
      {% for slide in page.collection('slider') %}
      {% set image = slide.header.image %}
      {% set url = slide.header.url %}
      <article data-id="post-{{ loop.index }}" class="post-{{ loop.index }} post type-post status-publish format-standard has-post-thumbnail hentry tag-no-excerpt is-featured" itemscope itemprop="blogPost" itemtype="http://schema.org/BlogPosting">
            {% if image %}
              <div class="site-banner-media">
                <figure class="site-banner-thumbnail" title="{{ slide.title }}" itemprop="image">
                  <img width="1920" height="640" src="{{ theme_url }}/images/slideshow/{{ image }}" class="attachment-receptar-banner size-receptar-banner wp-post-image" alt="{{ slide.title }}"/>
                </figure>
              </div>
            {% endif %}
            {% if slide.title %}
              <div class="site-banner-header">
                <h1 class="entry-title" itemprop="name">
                  <a href="{{ url }}" class="highlight" rel="bookmark">{{ slide.title }}</a>
                </h1>
              </div>
            {% endif %}
      </article>
    {% endfor %}
  </div>
</div>
👍 2
2 years ago

Thank you very much for the time invested in your detailed answer, I will try it.

@q3d:
Placing slider data in the site.md file is not a very flexible solution. ...

I agree with you 👍.
Regards
joejac

2 years ago

Thank you, @joejac! My answer is just a suggestion, and I'm sure you'll find the right solution. I often treat ready-made templates as inspiration for my own implementations.

👍 1
2 years ago

Hello q3d text and links work perfectly, but images are not taken from their corresponding subdirectories:

@q3d:
subdirectories for each slide, e.g., pages/slider/01._slide-1, pages/slider/02._slide-2

This is because images are taken from the original directory under the theme/images which is not available to the user via the admin panel.
src="{{ theme_url }}/images/slideshow/{{ image }}"

TWIG
<figure class="site-banner-thumbnail" title="{{ slide.title }}" itemprop="image">
                  <img width="1920" height="640" src="{{ theme_url }}/images/slideshow/{{ image }}" class="attachment-receptar-banner size-receptar-banner wp-post-image" alt="{{ slide.title }}"/>
                </figure>

Since each image is in a different subdirectory I can not have a common path, is there a way to solve this or place all images inside the same directory available to the admin panel?

It will not be easier to have all titles, images, and URL data for all the slides inside only one default.en.md file, so we can have a default.es.md, too, with all corresponding titles, images, and URL data inside. If I remember well, the Deliver theme has it in this way, but the slider is different, and that implies modifying a lot of the code, which is pretty difficult for me. Sorry.

2 years ago

Ok, solved the images, sorry to get it so slowly, I uploaded all images to the slider directory, and then in user/themes/myinheritedreceptar/templates/partials/slider.html I changed the path to: src="user/pages/slider/{{ image }}" is really easy, thanks q3d

TWIG
<figure class="site-banner-thumbnail" title="{{ slide.title }}" itemprop="image">
                  <img width="1920" height="640" src="user/pages/slider/{{ image }}" class="attachment-receptar-banner size-receptar-banner wp-post-image" alt="{{ slide.title }}"/>
                </figure>

The admin panel has all images inside a single directory: pages/slider.

last edited 11/05/24 by Jose
2 years ago

I'm glad I could help! 😊 There's always room to improve things; I just tried to help get you started. Depending on your needs, the images could, for example, be placed inside subdirectories within the slider folder, with references dynamically fetched in a loop and in the file: user/themes/receptar/templates/partials/slider.html.twig:

PHP
{{ set image = page.media.images|first }}

and then insert the image as described in the documentation.

I can’t check or provide a ready solution right now since I'm cooking soup 😉

2 years ago Solution

Thanks q3d,
Guided by your hints I got a compact solution:

  1. I created in /pages/01-home the files: blog.en.md and blog.es.md
  2. In the header of each one I placed the title, image and URL related to each language
YAML
slider:
  - 
    image: slide1.jpg
    title: 'Title 1'
    url: "#"
  - 
    image: slide2.jpg
    title: 'Title 2'
    url: "#"
  - 
    image: slide3.jpg
    title: 'Title 3'
    url: "#"

  1. I uploaded all the images to: /pages/01-home
  2. In the template: `user/themes/myreceptarinherit/templates/partials/slider.html.twig I changed line 3 for this:
    TWIG
    {% for slide in page.header.slider %}
    

    4.1 I also changed the image path on line 8 to:
    {{ base_url_simple }}/user/pages/01.blog/

    TWIG
    <img width="1920" height="640" src="{{ base_url_simple }}/user/pages/01.blog/{{ slide.image }}" class="attachment-receptar-banner size-receptar-banner wp-post-image" alt="{{ slide.title }}"/>
    

    Finally, all data and images are accessible via Grav Admin panel.
    Thanks a lot.

last edited 11/05/24 by Jose
2 years ago

Great solution, @joejac! Organizing the slider content in the header of each language file is a smart, efficient way to manage multilingual content. I think my approach might have been a bit overcomplicated. Your setup makes it easy to edit everything directly through the Grav Admin panel. Thanks for sharing the details!

👍 1

Suggested topics

Topic Participants Replies Views Activity
Themes & Styling · by Pedro M, 2 months ago
4 193 2 months ago
Themes & Styling · by Ian, 2 months ago
3 90 2 months ago
Themes & Styling · by Norbert, 2 years ago
11 449 3 months ago
Themes & Styling · by Lukáš Findeis, 3 months ago
0 43 3 months ago
Themes & Styling · by Sebadamus, 4 months ago
5 123 3 months ago