Skip to content

Using limit() on collection breaks iterator.isLast #161

Open

Description

@samsauter

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.

Activity

  1. changed the title [-]Limiting collection breaks iterator.isLast[/-] on Dec 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions