Hello everybody,
I've created a view with the machine name 'more_work', wich display all items in an unformatted list and I've created an algorithm in bartik core theme's templates (core/themes/bartik/templates/views/views-view-unformatted--more_work.html.twig).
The code looks like this
{#
/**
* @file
* Theme override to display a view of unformatted rows.
*
* Available variables:
* - title: The title of this group of rows. May be empty.
* - rows: A list of the view's row items.
* - attributes: The row's HTML attributes.
* - content: The row's content.
* - view: The view object.
* - default_row_class: A flag indicating whether default classes should be
* used on rows.
*
* @see template_preprocess_views_view_unformatted()
*/
#}
{% if title %}
<h3>{{ title }}</h3>
{% endif %}
{% set i = random(1,(rows|length)/2) %}
{% for row in rows %}
{% if loop.index == i %}
{%
set row_classes = [
default_row_class ? 'views-row',
]
%}
<div{{ row.attributes.addClass(row_classes) }}>
{{- row.content -}}
</div>
{% endif %}
{% endfor %}
{% set i = random(((rows|length)/2)+1,rows|length)%}
{% for row in rows %}
{% if loop.index == i %}
{%
set row_classes = [
default_row_class ? 'views-row',
]
%}
<div{{ row.attributes.addClass(row_classes) }}>
{{- row.content -}}
</div>
{% endif %}
{% endfor %}
{{ rows|length }}
The algorithm display only two elements in view from random index positions. The problem is that it is works only when I clear the cache but I want to make it work like that when I reload the page. For that reason I would like to know if I could make a certain php file through I can create functions with the same work principle as random(1,(rows|length)/2) or random(((rows|length)/2)+1,rows|length) wich I can then use in this twig file, or if I could modify my view with a custom module somehow.
Would you help me to fix it?
Thanks