Flowpack.ElasticSearch.ContentRepositoryAdaptor icon indicating copy to clipboard operation
Flowpack.ElasticSearch.ContentRepositoryAdaptor copied to clipboard

Using limit() on collection breaks iterator.isLast

Open samsauter opened this issue 8 years ago • 0 comments

I have the following setup to limit a collection and return it as json. But iterator.isLast is not true in the last cycle, so the json format is wrong because the last ',' is not removed. Did I miss something in the config or my fusion setup?

prototype(Vendor.Site:NewsListJson) < prototype(TYPO3.TypoScript:Collection) {
	collection = ${Search.query(site).nodeType('Vendor.Site:News').sortDesc('date').limit(5).execute()}
	itemName = 'node'
	iterationName = 'iterator'
	itemRenderer = Vendor.Site:NewsListItemJson {

	}

	@process.1 = ${'[' + value + ']'}
	@cache {
		mode = 'cached'
		entryTags {
			1 = ${'NodeType_Vendor.Site:News'}
		}
	}
}
prototype(Vendor.Site:NewsListItemJson) < prototype(Vendor.Site:JsonObjectRenderer) {
	id = ${q(node).property('uriPathSegment')}
	title = ${String.stripTags(q(node).property('title'))}
	text = ${String.crop(q(node).property('text'), 150, '...')}
	image = TYPO3.Neos:ImageUri {
		asset = ${q(node).property('image')}
		maximumWidth = 80
		maximumHeight = 60
		allowCropping = TRUE
		allowUpScaling = TRUE
	}
	entryDate = ${Date.format(q(node).property('date'), 'F jS, Y')}
	category = ${q(node).property('category')}
}
prototype(Vendor.Site:JsonObjectRenderer) < prototype(TYPO3.TypoScript:RawArray) {
	@process.1 = ${Json.stringify(value)}
	@process.2 = ${'' + value}
	@process.3 = ${iterator.isLast ? value : value + ','}
}

Output of ${iterator}: [{"index":0,"cycle":1,"isFirst":true,"isLast":false,"isEven":false,"isOdd":true},{"index":1,"cycle":2,"isFirst":false,"isLast":false,"isEven":true,"isOdd":false},{"index":2,"cycle":3,"isFirst":false,"isLast":false,"isEven":false,"isOdd":true},{"index":3,"cycle":4,"isFirst":false,"isLast":false,"isEven":true,"isOdd":false},{"index":4,"cycle":5,"isFirst":false,"isLast":false,"isEven":false,"isOdd":true},]

Using: Flowpack.ElasticSearch.ContentRepositoryAdaptor from master branch Neos 2.3.8

Thank you.

samsauter avatar Dec 16 '16 14:12 samsauter