Questions & Answers

cpe
Elite Observer

Get content as simple text from DOMTABLE like getting table within DOM with toText

Dear Community,

I am working on a TemplateSet for a search and I am extracting all content as simple text for our customer.

CMS_INPUT_TEXT is obvious.
CMS_INPUT_DOM has the function toText, which works fine and also handles tables within the DOM fine.
CMS_INPUT_DOMTABLE sadly has no toText available and no other method giving the desired output.

Any help appreciated in getting the simple text equivalent from toText out of the DOMTABLE!

Cheers
Connz

0 Kudos
3 Replies
hoebbel
Crownpeak employee

Hello Connz,

I would try the table function. You can use it to output tables as required. This will get rid of the table, tr and td format templates.
If format templates are also used within the table cells, it becomes more difficult if their output has not been configured accordingly for the text output channel anyway...

Instead of using the table function, you can also modify the corresponding format templates (table, tr, td). However, this doesn't solve the problem of the format templates used within the cell contents.

Best regards
Holger

0 Kudos

Hey Holger,

I have custom format templates (table, tr, td) anyway and there are only a few other format templates used, so I think adjusting the output there would be the most fitting.

I tried that first, but run into this strange issue:

If I leave the initial $CMS_VALUE(#content)$ in all format templates, I get the output I want directly. The problem is, that I am going through all content and collection all texts in a variable to insert into JSON at the end. So I would need something like:

$CMS_SET(void, set_description.add(#content))$

I put that in the td and it results in "de.espirit.firstspirit.generate.ElementRenderer$ChildPrinter@..." for every cell in the set_description.

I then tried saving the output in a set variable and using that:

$CMS_SET(set_content)$
	$CMS_VALUE(#content)$
$CMS_END_SET$
$CMS_SET(void, set_description.add(set_content))$

When I output set_content with CMS_VALUE is it set correctly, but I get "\n\t$CMS_VALUE(#content)$\n" in my set_description.

In the table function I also have to handle #content, so I think that would result in the same issues?

I think I am on the wrong element here because of the other Format Templates like p/li/u/i/etc. But they can be nested within each other, so I would not know where to put the set_description and where just output #content.

Do you have another hint for me?

Cheers
Connz

0 Kudos
cpe
Elite Observer

PS:

Ich habe eine Lรถsung, aber sie ist... sieh selber:

Ich habe in dem Template, in dem ich das DOMTABLE habe, ein hidden DOM hinzugefรผgt und dann klappt das hier:

$CMS_SET(void, st_hidden_dom_for_json.set(st_table.getDom()))$
$CMS_SET(void, set_description.add(st_hidden_dom_for_json.toText(false).trim()))$

Wenn jemand noch eine andere Lรถsung hat, die sich besser anfรผhlt, dann gerne her damit! ๐Ÿ™‚

0 Kudos

Type a product name