В модели Product.php
public $belongsToMany = [
'categories' => [
'Ezasoft\Products\Models\Category',
'table' => 'ezasoft_products_relations',
'order' => 'title'
]
];
В модели Category.php
public $belongsToMany = [
'products' => [
'Ezasoft\Products\Models\Product',
'table' => 'ezasoft_products_relations',
'order' => 'title'
]
];
В странице products.htm
title = "Products"
url = "/:slug"
layout = "default"
is_hidden = 0
[builderDetails]
modelClass = "Ezasoft\Products\Models\Product"
identifierValue = "{{ :slug }}"
modelKeyColumn = "slug"
displayColumn = "title"
notFoundMessage = "Record not found"
==
<h1>ПРОДУКЦИЯ</h1>
{% set record = builderDetails.record %}
{% set displayColumn = builderDetails.displayColumn %}
{% set notFoundMessage = builderDetails.notFoundMessage %}
{% if record %}
{{ attribute(record, displayColumn) }}
{{ record.description | raw }}
{% else %}
{{ notFoundMessage }}
{% endif %}
В странице product_list.htm
title = "product_list"
url = "/"
layout = "default"
is_hidden = 0
[builderList]
modelClass = "Ezasoft\Products\Models\Product"
scope = "-"
scopeValue = "{{ :scope }}"
displayColumn = "title"
noRecordsMessage = "No records found"
detailsPage = "products"
detailsKeyColumn = "slug"
detailsUrlParameter = "slug"
pageNumber = "{{ :page }}"
==
{% set records = builderList.records %}
{% set displayColumn = builderList.displayColumn %}
{% set noRecordsMessage = builderList.noRecordsMessage %}
{% set detailsPage = builderList.detailsPage %}
{% set detailsKeyColumn = builderList.detailsKeyColumn %}
{% set detailsUrlParameter = builderList.detailsUrlParameter %}
{% for category in categories %}
{{ category.title }}
{% endfor %}
{{ record.category }}
<ul class="record-list">
{% for record in records %}
<li>
{# Use spaceless tag to remove spaces inside the A tag. #}
{% spaceless %}
{% if detailsPage %}
<a href="{{ detailsPage|page({ (detailsUrlParameter): attribute(record, detailsKeyColumn) }) }}">
{% endif %}
{{ attribute(record, displayColumn) }}
{% if detailsPage %}
</a>
{% endif %}
{% endspaceless %}
</li>
{% else %}
<li class="no-data">{{ noRecordsMessage }}</li>
{% endfor %}
</ul>
{% if records.lastPage > 1 %}
<ul class="pagination">
{% if records.currentPage > 1 %}
<li><a href="{{ this.page.baseFileName|page({ (pageParam): (records.currentPage-1) }) }}">← Prev</a></li>
{% endif %}
{% for page in 1..records.lastPage %}
<li class="{{ records.currentPage == page ? 'active' : null }}">
<a href="{{ this.page.baseFileName|page({ (pageParam): page }) }}">{{ page }}</a>
</li>
{% endfor %}
{% if records.lastPage > records.currentPage %}
<li><a href="{{ this.page.baseFileName|page({ (pageParam): (records.currentPage+1) }) }}">Next →</a></li>
{% endif %}
</ul>
{% endif %}
Пытаюсь безуспешно выдернуть названия категорий так
{% for category in categories %}
{{ category.title }}
{% endfor %}