The “page fields” that I have set up in the module are not working properly, and the website pages called up are sometimes displayed and sometimes not, even though I have indeed set them up.
■My creation flow
1. I create an original module and prepare “page field”. The website page set here is selected and displayed on the front end.
2. I want to enable multiple selection of page fields. Therefore, the “page field” will be repetitive.
3. Put the item to be looped in the “content_by_id” function as an argument.
4. Output the looped content as a li tag and call absolute_url, page_title and meta_description.
■Problem
The website pages set in the “module.seminar_page_select” page field may or may not be displayed.
For example, only 2 pages appear on the actual front end, even though I have indeed set 4 in the page edit screen.
This is also true in the editor during editing, and the behavior is unstable. I think there were a few times when it worked.
For example, if I set 3 items, there were times when 3 items appeared.
The “module.library_page_select” is a page field with the same mechanism, but the display here is normal.
Rather, when “module.library_page_select” is updated, the above bug seems to occur more often.
It may be that something is interfering or overriding each other.
This is a mystery, but the JSON information for the pages set in “module.library_page_select” does indeed store 3 items.
However, only the first two are actually displayed. In other words, the following “178222335333” is not displayed.
“seminar_page_select”: [
181559445858,
182462472079,
178222335333
],
■Source code in question
<ul>
<li>
{% if module.library_page_select %}
<ul>
{% for library_item in module.library_page_select %}
{% set library_content = content_by_id(library_item) %}
{% if library_content %}
<li>
<a href="{{ library_content.absolute_url }}">
<h3>{{ library_content.page_title }}</h3>
<p>{{ library_content.meta_description }}</p>
</a>
</li>
{% endif %}
{% endfor %}
</ul>
{% endif %}
</li>
<li>
{% if module.seminar_page_select %}
<ul>
{% for seminar_item in module.seminar_page_select %}
{% set seminar_content = content_by_id(seminar_item) %}
{% if seminar_content %}
<li>
<a href="{{ seminar_content.absolute_url }}">
<h3>{{ seminar_content.page_title }}</h3>
<p>{{ seminar_content.meta_description }}</p>
</a>
</li>
{% endif %}
{% endfor %}
</ul>
{% endif %}
</li>
</ul>
■Cause?
I thought it might be due to the fact that the pages were drafts, not published, but they all had a published status. So the status of the page does not seem to be the cause.
Is something overwriting the page? The one that does not display well is the “seminar_page_select” one. There is no case that “library_page_select” was not displayed, but when “library_page_select” is updated, the articles in “seminar_page_select” disappear. (e.g. there should have been 3 articles in the front end, but there are now 2 articles).
This may be because the for loop is not working properly.