using locate folder and displaying its contents
I created an asset factory to create video blocks and put them in a specific folder.. I'd like to use the locate folder tool to display all those videos on a page...
can I use the locate folder tool or do I have to use the locate block tool? having a hard time getting this piece started...
as always, thanks in advance!
Discussions are closed to public comments.
If you need help with Cascade CMS please
start a new discussion.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
1 Posted by Ryan Griffith on 05 Feb, 2016 04:28 PM
Hi,
You can definitely use
locateFolder
assuming you need the children of that specific folder.What you would do is use
locateFolder
and loop over the returned object'schildren
property. Each child will effectively be each Block object that you can run things likegetStructuredDataNode
on to obtain their content.Please let me know if you have any questions.
Thanks!
2 Posted by Nando on 05 Feb, 2016 04:55 PM
for testing, I'm trying something like this and its not working :(
I should be getting like 7 instances of the #1... no?
3 Posted by Nando on 05 Feb, 2016 04:58 PM
my mistake... I had to use #set ($videos = $vlocation.children) and it worked!
can i get the blocks from a subfolder without specifying the subfolder?
4 Posted by Ryan Griffith on 05 Feb, 2016 07:53 PM
Hi,
Correct, you would need to use
.children
to traverse the folder's contents.If you wanted to go into a subfolder, you would need to check the child's type to see if it's a folder and, if so, loop over it's children. I would recommend abstracting the processing of a folder into a macro so you can take advantage of recursion as opposed to nested loops.
Please let me know if you have any questions.
Thanks!
5 Posted by Nando on 05 Feb, 2016 07:59 PM
this is what I came up with and it works but I'm not sure if its right.. its checking all the subfolders...
not sure how to search for blocks only so i did it by datadef...
also, not sure how to get any more information in the addition to the name... was trying something like #set($title = $block..getStructuredDataNode("title").textValue) but no go...
thanks!
6 Posted by Ryan Griffith on 05 Feb, 2016 08:09 PM
Hi,
I picture something more like the following:
What you use depends on what data you need. If you need a static metadata field, it's as simple as
$block.metadata.title
, if dynamic metadata$block.metadata.getDynamicField("field-identifier")
, and if it's structured data (ie a data definition field) you would use either$block.getStructuredDataNode("path/to/identifier)
or$block.getStructuredDataNodes("path/to/identifier)
(if a multiple).For additional information on what properties are available for a particular object, use the Property Tool's
outputProperties
method:$_PropertyTool.outputProperties($block)
.Please let me know if you have any questions.
Thanks!
7 Posted by Nando on 05 Feb, 2016 08:21 PM
thanks!
testing your example code gives me an error:
8 Posted by Nando on 05 Feb, 2016 08:25 PM
If I dont check if its a folder, it works fine...
do I need it to check if its a folder? sub folders wont have sub folders...
9 Posted by Ryan Griffith on 05 Feb, 2016 08:41 PM
Whoops, my fault, there was a bug in my Format code.
The line that has
#traverseFolder($folder)
should read#traverseFolder($child)
. This was resulting in an infinite loop. Let me know how things work out after making this adjustment.Please let me know if you have any questions.
Thanks!
10 Posted by Nando on 05 Feb, 2016 08:43 PM
ah nice!
last thing, last thing...
how can I limit the number shown and order them... all of them, not just from each folder?
11 Posted by Ryan Griffith on 05 Feb, 2016 09:05 PM
Hi,
In that case, you would probably need to create an array of objects so you can check the size as well as sort by the object properties.Then, you would loop over the resulting array.
Now that I think of it, the Query API might be a better solution here. What you could do is query for blocks that have a specific Metadata Set and limit it to a specific number and add them to the lookup table I mentioned above. Something like the following:
Please let me know if you have any questions.
Thanks!
12 Posted by Nando on 05 Feb, 2016 09:10 PM
hmmm.. I'm not sure where to put that in relation with the code you provided before... where would i set the folder to query?
13 Posted by Nando on 06 Feb, 2016 01:22 AM
so no query by folder, got it...
but since I need it by folder, I've done the following::
few things:
I can't get the created date to come up
only 2 blocks show when there are about 8 in the video subfolders (all blocks have the same metadata set) 1 video from each subfolder
how would I sort by created date? newest and/or oldest
14 Posted by Ryan Griffith on 08 Feb, 2016 12:02 PM
Hi,
Sounds like we're getting closer.
One thing I would recommend is to move the parent folder check into the first
foreach
loop, this way you have less to sort for the second loop.Try using
"date": $block.createdOn
instead of"date": $block.created-on
.My fault, the snippet I provided was a little incorrect within that second loop. Note that you are using a map in the second loop, so accessing the properties from the first loop would be done using
get("KEY")
. For example, you get the path:You would tweak the second sort parameter passed to the Sort Tool from
"name:asc"
todate:asc
(ordesc
). Additionally, you can add multiple sort criteria by supplying an array of items. For example:Please let me know if you have any questions.
Thanks!
15 Posted by Nando on 08 Feb, 2016 02:03 PM
closer and closer!
this is what i have now
I moved the parent folder check up as you suggested and that works fine...
still only have 2 blocks showing, I'm not sure where I should use the get(xx) since everything is pulling already...
Also, for the created date - is there anyway to modify the output?
thanks again
16 Posted by Ryan Griffith on 08 Feb, 2016 04:33 PM
Hi,
Curious, what is the size of
$blocks
and what is the resulting size of$videoArr
?For the
get()
usage, you would replace the following:with:
You would use the Date Tool's
format
method to format the date. For example:would result in something like
Mon, Feb 8, '16
. For more information about available formatting options, see this page.Please let me know if you have any questions.
Thanks!
17 Posted by Nando on 08 Feb, 2016 05:22 PM
hmmmm...
$blocks.size() = 10 and $videoArr.size() = 2
18 Posted by Nando on 08 Feb, 2016 05:25 PM
I see whats happening... the query is only showing 10 results before my parent folder check... can I can my parent folder check in the query?
19 Posted by Nando on 08 Feb, 2016 06:13 PM
got it! I limit it by count on the video foreach...
thoughts? issues with 1000 max results?
thanks again!
20 Posted by Ryan Griffith on 08 Feb, 2016 06:18 PM
Ah, that makes sense.
Another way to accomplish this would be to
#break
out of the loop when$videoArr.size()
reaches 10 blocks:Note: the query tool will trim results to 500 items, so that 1000 value won't do anything.
I'm going to go ahead and close this discussion, please feel free to comment or reply to re-open if you have any additional questions.
Have a great day!
Ryan Griffith closed this discussion on 08 Feb, 2016 06:18 PM.
Nando re-opened this discussion on 11 Feb, 2016 04:53 PM
21 Posted by Nando on 11 Feb, 2016 04:53 PM
Sorry to reopen but I just wanted to mention that querying by folder would have been WAY easier and less load heavy so I suggested it :)
http://ideas.hannonhill.com/forums/52559-cascade-cms-ideas/suggesti...
22 Posted by Ryan Griffith on 11 Feb, 2016 06:36 PM
Not a problem at all, thank you for contributing to our Idea Exchange!
We actually have an existing suggestion that mentions filtering by folder as an option. To help keep things tidy, I am going to merge the two suggestions.
Again, thank you for contributing.
Have a great day!
Ryan Griffith closed this discussion on 11 Feb, 2016 06:36 PM.