How you can read the page properties with a custom macro?
Asked by Patrick Doucet:

*This question is in reference to Atlassian Documentation: [Page Properties Macro](https://confluence.atlassian.com/pages/viewpage.action?pageId=184550024)*

I would like to read the page properties and display the result in a custom layout.

I know the Free Plugin "GetMetadata" from Comala but with this plugin I can't read metadata in another page...

Can you help me?

Thank you!


Answers:
author: BKippelt
body: Does anyone have an example of a PagePropertyExtractor class in Java that can read the page properties from the page body?

I want to build a simple search with which I can filter for the page properties. Now it would only work afterwards. That means, I search for pages by title and filter the result by the specified page properties.

<https://community.atlassian.com/t5/Confluence-questions/How-can-I-filter-my-Confluence-search-by-page-properties/qaq-p/953887#M126706>


author: Steven F Behnke
body: It is not possible to lift the content of the 'page properties macro' directly. I'd like explain the difference between some things here --

* The question is pertaining to the **Page Properties Macro** , which is a page macro inserted into a page. A while in the past, this macro was called the **Metadata Macro** . It is called **{details}** in the storage format. Again, this has no direct API.
* Bill Bailey is referring to the storage mechanism **Properties**, which can be applied to various content types in Confluence via the public APIs.

I believe the **Page Properties Report** macro ++searches++ for **pages** with the correct **labels** on them, ++parses++ the page content for the **Page Properties** **Macros** , and then pulls the interior **\<table\>** element for reporting. You would have to do the same to obtain the data inside the macro.

comments: author: Steven F Behnke
body: The JAVA API I am sure would be preferable due to speed. You could use the REST API to use a CQL query like such -- https://confluence.example.com/dosearchsite.action?cql=siteSearch+~+%22macroName%3Adetails%22+and+type+%3D+%22page%22+and+label+%3D+%22my-label%22&queryString=macroName%3Adetails


author: Patrick Doucet
body: "You would have to do the same to obtain the data inside the macro."

Yes...And How I do that? I need to do that, i woluld like a custom layout.

Thank you


author: Bill Bailey
body: If you want to display data on the *same* page it is stored, the only solution I know of (and have used) is via the metadata plugin.Since it is free (and has been for years), that is the best/easiest solution.

Where I got the syntax was from here: <https://help.k15t.com/scroll-pdf-exporter/using-page-properties-as-placeholder-101157314.html>

But even if that method is available, I typically have based variables using the metadata plugin.


author: Patrick Doucet
body: Hello Bill,

**To use page properties as placeholders:**

1. Open the root page of your exports.
2. Insert a page properties macro to your page and a two-column key-value table.  
   ![information](/html/@4DF2F60CA30FBCA0CD7B960B5D0F871B/images/emoticons/information.png "information") The first column of the table will be the keys and the second one will be the corresponding values.
3. Save the page.
4. Open your template and insert the placeholder in the following pattern:$pageProperty.from("User")  
   ![information](/html/@4DF2F60CA30FBCA0CD7B960B5D0F871B/images/emoticons/information.png "information") Please note that the placeholders are case-sensitive.  
   This placeholder will be replaced with the corresponding value stored in the content properties macro for the key with name "User".

5. If you have multiple page property macros on your root page, you have to assign an ID to the macros and refer to this ID in your template.  
   For example:$pageProperty.from("User", "123")  
   This placeholder will be replaced with the corresponding value stored in the content properties macro with ID 123.

Step 1 : OK

Step 2 : OK

Step 3 : OK

Step 4 : ??? I need more explanation...

Step 5 : OK


author: Bill Bailey
body: This is in reference to K15t velocity templates, but could give you a clue of how to address them (I haven't tried this). I am assuming that it will display the value on the page.

From the metadata plugin, there is the following method:

```
getMetadataValues(String token, String spaceKey, String pageName)
```

<https://comalatech.jira.com/wiki/display/META/Metadata+plugin+version+1+documentation#Metadatapluginversion1documentation-metadata-reportmacro>


author: Patrick Doucet
body: So... How I can use it?

In a macro like this?

\<p\>  
\<ac:structured-macro ac:macro-id="5b3f7bcc-12c8-4b82-afd6-93e41192cfb5" ac:name="metadata-values" ac:schema-version="1"\>  
\<ac:parameter ac:name="0"\>Source\</ac:parameter\>  
\<ac:parameter ac:name="1"\>SGDE\</ac:parameter\>  
\<ac:parameter ac:name="2"\>SYS-0004\</ac:parameter\>  
\</ac:structured-macro\>  
\</p\>

1. Source is the key
2. SGDE is the space name
3. SYS-0004 is the page name

This macro doesn't work...


author: Patrick Doucet
body: Hello,

I tried $pageProperty.from("Field1") in a page with a property "Field1" but It doesn't work...

Where did you find the name of this calss? I didn't find it in the <https://docs.atlassian.com/atlassian-confluence/5.9.9/>.

My macro is:

-------------------------------------------------------------------------------------------------

## Developed by: \<your name\>  
## Date created: 27/07/2016

## @param filter:title=Filter\|type=string\|required=false\|desc=Label filter

\<li\>$pageProperty.from("Source")\</li\>

-------------------------------------------------------------------------------------------------


author: Bill Bailey
body: I think it is of the form: $pageProperty.from("User") where User is the key. And $pageProperty.from("User", "123") when you have macros with IDs.

How to access from another page, I am not clear on, but maybe this gets you started and you can report back?


Tags: page-property