grav-plugin-tntsearch
grav-plugin-tntsearch copied to clipboard
Indexing Modular and Custom Field Content with Flex Pages
I'm not able to get modular and custom field content indexed with Flex Pages enabled, despite creating a template as explained in the docs.
I have a modular page with a few modules that use a custom blueprint:
modular.en.md
infolist.en.md
infolist.en.md
infolist.en.md
The following YAML appears in modular.en.md
:
content:
items: '@self.modular'
The module page content in infolist.en.md
looks like this:
<p>We are the XYZ experts, from a very-unique-word and more.</p>
The modular page custom field content in infolist.en.md
looks like this:
listitems:
-
itemtitle: Something
itemimage: someimage.jpg
itemimageloc: center
itemicon: null
itemiconloc: null
itemdesc: '<p>A bit of text with another-very-unique-word in it.</p>'
I've created a templates/tntsearch/modular.html.twig
file to capture modular and custom field content:
{% for module in page.collection() %}
<p>
{{ module.content }}
{% for info in module.listitems %}
{{ info.itemtitle }}
{{ info.itemdesc }}
{% endfor %}
</p>
{% endfor %}
{{ page.content }}
When I index the site, I get only the parent modular.en.md
page content, and nothing from the infolist.en.md
module page content or custom field.
Could this be related to the lack of Flex Page support for @self
in blueprints as noted at Page Blueprint with filepicker field does not recognize folder value of @self?
The @self
issue in filepicker should be separate to this one (upload handling was missing support for it); modular pages should work just like they do with the regular pages.
I need to take a look what's going on here...
OK, let me know if you need more information.
You are missing:
tntsearch:
template: 'tntsearch/modular.html.twig'
content:
items: '@self.modular'
Er, thanks ( :embarrassed: )
I've added that to all modular pages, rebuilt the TNT Index, and cleared the cache. There is still no sign of page.content, itemlist.itemtitle, or itemlist.itemdesc text from infolist.en.md in the search results. Worse, the parent modular.en.md page content (the "very-unique-word" example above) is no longer being found either. When I remove the tntsearch: from the header, the parent page content is restored in the search results.
Another data point: if I drop the templates/tntsearch/modular.html.twig
into a parent page, the content of the child modules is rendered:
{% for module in page.collection() %}
<p>
{{ module.content }}
{% for info in module.listitems %}
{{ info.itemtitle }}
{{ info.itemdesc }}
{% endfor %}
</p>
{% endfor %}
{{ page.content }}
You mean if you put the modules into the main template of the page it works?
Does this new code work in the regular pages, btw?
Hi - meant to update this issue. I reach out to Trilby for paid support and @rhukster was able to get my site working for launch. The changes he came up with were:
- Turned off front-end Flex pages.
- Replaced
tntsearch:
template: 'tntsearch/modular.html.twig'
with
tntsearch:
template: 'tntsearch/modular'
- Changed
user/data/gantry5/themes/rt_photon/templates/tntsearch/modular.html.twig
to:
{% for module in page.collection() %}
{{ module.content|raw|striptags }}
{% for info in module.header.listitems %}
{{ info.itemtitle|raw|striptags }}
{{ info.itemdesc|raw|striptags }}
{% endfor %}
{% endfor %}
{{ page.content|raw|striptags }}
The |raw|striptags
was to remove unwanted characters that were getting in somehow.