grav-plugin-tntsearch icon indicating copy to clipboard operation
grav-plugin-tntsearch copied to clipboard

Indexing Modular and Custom Field Content with Flex Pages

Open thekenshow opened this issue 4 years ago • 7 comments

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?

thekenshow avatar Sep 30 '20 15:09 thekenshow

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...

mahagr avatar Oct 02 '20 07:10 mahagr

OK, let me know if you need more information.

thekenshow avatar Oct 02 '20 14:10 thekenshow

You are missing:

tntsearch:
  template: 'tntsearch/modular.html.twig'
content:
    items: '@self.modular'

mahagr avatar Oct 09 '20 07:10 mahagr

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.

thekenshow avatar Oct 09 '20 13:10 thekenshow

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 }}

thekenshow avatar Oct 13 '20 13:10 thekenshow

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?

mahagr avatar Oct 21 '20 07:10 mahagr

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:

  1. Turned off front-end Flex pages.
  2. Replaced
tntsearch:
  template: 'tntsearch/modular.html.twig'

with

tntsearch:
  template: 'tntsearch/modular'
  1. 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.

thekenshow avatar Oct 21 '20 12:10 thekenshow