Get first two paragraphs from a News Item


(Nic Hubbard) #1

Matrix Version: 5.4.3.1

We are building a new website and on our news listing page we would like to show a lot more text for each item than we had previously (last 10 years) put in the News Item summary field.

My idea was to use a keyword modifier and grab the first two HTML p elements from the body keyword and use those, but I am not seeing a way to do this.

Any ideas?


(Bart Banda) #2

Either by using some SSJS to process the HTML of the content and do your logic in JS for getting the first two

s or using some sort of regex replace to replace everything after the second

with nothing?

I’ve done it with 1

in the past with something like:

%asset_contents_raw^replace:\/p>.*:/p>%


(Peter McLeod) #3

Hi
Could try the xpath keyword - something like:

<p>%asset_contents_raw^tag:div^xpath:</p><p>://p[position() < 3]%</p>

It would depend on the content being valid xml though - which is why I’ve wrapped it in a div in case there is no parent node.

Thanks
Peter