Get a piece of metadata off the current page
I've made a piece of custom metadata on a page that holds a date value. I'm currently getting the create date from the page, but I can't figure out how to get this metadata date. My plan is to check to see if the date is there. If it is, I'll use it, if not, I'll use the create date. How do I get it? I tried doing the trick of creating a format and looking at the current page, but that didn't seem to work.
This discussion was closed! See this FAQ for more information:
-
Create a Calling Page Index Block
See more..This Index Block, which is usually referred to as a
calling page
orcurrent page
Block, is one of the most used Blocks in Cascade. To further explain the purpose behind it's functionality, this Block will access the stored content for whatever Page you are currently looking at and load it into what region this Block is assigned to.To create the Index Block:
- Navigate to the BaseFolder → _cascade ...
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
webadmin closed this discussion on 17 May, 2016 06:27 PM.
webadmin re-opened this discussion on 17 May, 2016 06:33 PM
1 Posted by webadmin on 17 May, 2016 06:33 PM
Actually, I'm still having problems. I can't seem to request the metadata that I added. I'm not sure how to ask for that. Here's the XML:
I see how to get things like date and author. How do I get my metadata date?
2 Posted by Ryan Griffith on 17 May, 2016 07:01 PM
Hi,
To confirm, are you referring to the created-on timestamp? If so, check your Index Block and make sure the System Metadata option is checked.
Please let me know if you have any questions.
Thanks!
3 Posted by webadmin on 17 May, 2016 07:18 PM
No, I can get the created-on timestamp. I can't figure out how to get the date value out of the dynamic-metadata item (in this case, 1-1-2008).
4 Posted by Ryan Griffith on 17 May, 2016 07:32 PM
Ah, I see.
You can use the XPath Tool to obtain the value of the field:
Alternatively, you can use the Cascade API and bypass the Index Block all-together:
Note: if you need to do any sort of formatting (based on either example above), you will need to convert the string into a Date object using the Date Tool:
Please let me know if you have any questions.
Thanks!
5 Posted by webadmin on 17 May, 2016 07:58 PM
Neither seem to be working. You have an extra ] in the first set of code, but I removed it. In both cases, all I get for output is the variable name itself.
6 Posted by Ryan Griffith on 17 May, 2016 08:03 PM
My apologies for the extra square bracket in the snippet I provided.
The date formatting snippet I provided was meant to be an example, so it won't work if you are using the XPath snippet. To get it working, try the following:
Please let me know if you have any questions.
Thanks!
7 Posted by webadmin on 17 May, 2016 08:06 PM
It's still not working, but I think I see why. I'm trying to get the data out of the current page WITHOUT having an index associated with it. When I get the image URL, for example, I don't have to assign an index page to it. I'm able to access it directly by this code:
But when I use the code you gave me, it looks like it's not returning anything.
8 Posted by Ryan Griffith on 17 May, 2016 08:15 PM
Ah, I see.
You will need to attach an Index Block to the region in order to access the rest of the data. The DEFAULT region is slightly different in that if you do not apply an Index Block the
$contentRoot
variable will content the page's Structured Data, orpage-xhtml
if there is no Data Definition applied.Please let me know if you have any questions.
Thanks!
9 Posted by webadmin on 18 May, 2016 07:46 PM
So, does this mean that I'll have to attach an index to each page? Will it have to be one made for that page, or can I attach one for the whole site?
10 Posted by Ryan Griffith on 18 May, 2016 08:22 PM
Hi,
Correct, if you would like to re-use this code you would need to ensure the region(s) that use the Format have an Index Block applied.
If you would like to avoid needing to use an Index Block, you can use the
$currentPage
and Cascade API to get the field. The following should give you the value of the field:Please let me know if you have any questions.
Thanks!
11 Posted by webadmin on 18 May, 2016 09:12 PM
The $currentPage thing is what I'd like to do, but it doesn't seem to be working. I'm attempting to use these lines of code to read in the "Date" field:
All it's outputting is "Date is $date".
12 Posted by Ryan Griffith on 19 May, 2016 11:37 AM
My apologies, I was getting structured data fields mixed up with metadata fields.
When you have a moment, change
.textValue
to.value
.Please let me know if you have any questions.
Thanks!
13 Posted by webadmin on 19 May, 2016 12:54 PM
Perfect. That was it! Thanks!
14 Posted by Ryan Griffith on 19 May, 2016 01:49 PM
Thank you for following up, I am glad to hear the adjustment did the trick.
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 19 May, 2016 01:49 PM.