I have a block list with characterName, characterPhoto, and characterDescription for example... I've restricted it in the blocklist so you have to create exactly 4 items.
In the HTML template, the 4 characters are dotted around the page, not structured in a list or anything.
I'd like to access my items in the HTML directly like an array. Something like pageCharacter[0].characterName and further down the page use pageCharacter[1].characterName
I cannot use [] on the BlockListItem directly so how do I do this? The only way I know is to cycle through it using a foreach or something similar but this won't work in my case. Is there any way to do this?
A crude way would be to use .Skip(x) and .Take(1) to get at your items, but you are probably also able to convert the BlockListModel to an array by using a .ToArray<T>() or similar method, as it is derived from an IList (AFAIK).
I have used .ToList() and I can get string content from it fine using pageCharacter[0].Content.Value("characterName") but I can't work out how to get the URL from an image object this way?
I have tried
pageCharacter[0].Content.Value("characterImage").Url
and pageCharacter[0].Content.Value<IPublishedContent>("characterImage").Url
For example and both produce an error? Any pointers would be appreciated?
Accessing a BlockListItem directly like an array?
I have a block list with characterName, characterPhoto, and characterDescription for example... I've restricted it in the blocklist so you have to create exactly 4 items.
In the HTML template, the 4 characters are dotted around the page, not structured in a list or anything.
I'd like to access my items in the HTML directly like an array. Something like pageCharacter[0].characterName and further down the page use pageCharacter[1].characterName
I cannot use [] on the BlockListItem directly so how do I do this? The only way I know is to cycle through it using a foreach or something similar but this won't work in my case. Is there any way to do this?
Hi Craig,
A crude way would be to use
.Skip(x)
and.Take(1)
to get at your items, but you are probably also able to convert theBlockListModel
to an array by using a.ToArray<T>()
or similar method, as it is derived from anIList
(AFAIK).Hope this helps,
/Chriztian
Thank you,
I have used .ToList() and I can get string content from it fine using pageCharacter[0].Content.Value("characterName") but I can't work out how to get the URL from an image object this way?
I have tried
For example and both produce an error? Any pointers would be appreciated?
is working on a reply...