Skip to content
Docs

Developer guide

Layout repeat fields

Layouts often contain data where several items of the same shape repeat, such as sliders, banners, FAQs, and partner logos. In the past you had to declare dozens of variables like slider1_title, slider2_title … and implement reordering, adding, and deleting yourself.

With Zittme's repeat field, you only declare the fields of a single item, and the core automatically provides the following in the layout's detailed settings.

  • Adding / deleting items
  • Reordering by drag and drop
  • Visibility on/off + display period (start to end date): provided by default without declaring it
  • JSON storage and filtering by display conditions when rendering on the front end

A slider is just one use of this general-purpose feature.

1. Declaration: conf/info.xml

Wrap it in a <group> inside <extra_vars>, and put the fields of one item inside the <item> of a type="repeat" variable.

<extra_vars>
  <group>
    <title xml:lang="ko">첫 화면</title>
    <var name="visuals" type="repeat">
      <title xml:lang="ko">비주얼 슬라이드</title>
      <item>
        <var name="image" type="image"><title xml:lang="ko">배경 이미지</title></var>
        <var name="title" type="text"><title xml:lang="ko">제목</title></var>
        <var name="text" type="textarea"><title xml:lang="ko">설명</title></var>
        <var name="link_text" type="text"><title xml:lang="ko">버튼 이름</title></var>
        <var name="link_url" type="text"><title xml:lang="ko">버튼 링크</title></var>
        <var name="align" type="select" default="center">
          <title xml:lang="ko">문구 정렬</title>
          <options value="left"><title xml:lang="ko">왼쪽</title></options>
          <options value="center"><title xml:lang="ko">가운데</title></options>
        </var>
      </item>
    </var>
  </group>
</extra_vars>
  • The <var> elements inside <item> use the same types as regular extra_vars: text / textarea / image / select / checkbox / color, and so on.
  • A layout can have multiple repeat fields (for example, visuals and partners).
  • Always put them inside a <group>. The layout's detailed settings draw groups as tabs, so variables outside a group do not appear on screen.

2. Item fields added automatically

The core automatically manages the following fields for each item. You do not declare them yourself.

KeyMeaning
_idUnique item id (for tracking order and deletion)
_labelTitle shown in the admin list
_visibleWhether the item is shown (on by default)
_start_dateDisplay start date and time (empty means immediately)
_end_dateDisplay end date and time (empty means no end)

The array order is the display order. There is no separate order field.

3. Using it in templates: layout.html

In templates, the saved value arrives as $layout_info->{variable name} as an array of item objects. Filter by display conditions (on/off and period) with the LayoutModel::getVisibleItems() helper: there is no need to compare dates yourself.

@version(2)
@php
$slides = LayoutModel::getVisibleItems($layout_info->visuals ?? []);
@endphp

@if (count($slides))
<div class="my-slider">
  @foreach ($slides as $slide)
  <div class="slide" style="background-image:url('{{ $slide->image }}')">
    <h2>{{ $slide->title }}</h2>
    @if (!empty($slide->text))<p>{{ $slide->text }}</p>@endif
    @if (!empty($slide->link_text))<a href="{{ $slide->link_url }}">{{ $slide->link_text }}</a>@endif
  </div>
  @endforeach
</div>
@endif

The admin screen shows all items (including hidden ones), while the front end shows only items that pass through getVisibleItems().

4. Storage format

Values are stored in the layout instance as a JSON array of item objects. Dates use the YYYYMMDDHHIISS format, and images are uploaded file paths. You will not need to parse this yourself, but keep it in mind when building export or migration tools.

5. Limitations and cautions

  • A repeat field nested inside another repeat field is not supported.
  • There is no limit on the number of items, but we recommend keeping it under 20 for performance.
  • Make sure variable names do not overlap with existing regular extra_vars.
  • This feature is specific to Zittme. If you install the same info.xml on Rhymix, repeat fields are ignored (no error occurs).