How to render Meta Data for the current page

Topics: General
Dec 9, 2010 at 7:24 PM

Hi there!

Is there anyone that could point out some information how to render meta data for the current page?

What I would like to do is to have the standard content area on the page and some meta data fields that I would like to, for layout reasons, render on each page.

I have succeded to put the meta data on the page BUT as a list I know I should use a filter but please someone soon I'll have no hair left =)

BR Krezz 

Dec 9, 2010 at 7:51 PM

DataFacade.GetData<T>().FirstOrDefault(t => t.PageId == PageRenderer.CurrentPageId);

Where T is the type of your meta data
Dec 9, 2010 at 8:45 PM

Thanks for your reply, but does this mean that using Functions/Filters is out of the question?

Sorry for being a Noob =)

Dec 9, 2010 at 8:54 PM

Hi Krezz

>> I have succeded to put the meta data on the page BUT as a list I know I should use a filter but please someone soon I'll have no hair left =)

I guess you're adding an input parameter in an XSLT function and you're using .... Get<MetaDataType>Xml() function.

In this case you should choose Filter parameter, select "Function call" and choose "ActivePageReferenceFilter", it has one parameter, set it to "Current page". 

Dec 9, 2010 at 9:24 PM

Now we have had the C# and XSLT suggestions - in case you do not care much for C# or XSLT there is actually a third way which require no coding (but is less flexible) - Visual Functions.

  1. Go to the Functions perspective
  2. On "Visual Functions" add a new one
  3. Select your meta data type, click Next
  4. Give the function is some meaningful name / namespace, click Finish
  5. Now you get a WYSIWYG editor with your meta data fields - this is kind of a visual rendering template - you can move things round, switch to html view and customize.
  6. Go to "Visual Function Settings" tab and set the list length to 1 (this ,makes the preview more realistic)
  7. Preview - when you like what you see, Save

Next thing is to add the function to your template in the HTML where you want it and configure it to grab data for the current page.

  1. Edit your template
  2. Insert your Visual Function where you want it (using Insert | Function Markup)
  3. In the Function Properties dialog, select the parameter "List Filter", click "Function ..." and browse to the relevant ActivePageReferenceFilter function (same stuff @napernik described)

This will - when the page (template) renders call your Visual Function, pass a data filter saying "only this page" - then this data will be grabbed and rendered using your visual template.

I think this should work.


Dec 9, 2010 at 9:31 PM

Hi there napernik and mawtex!

You've made my day if you ever visit Sweden I owe you one or probably more than that =)

Med Vänliga Hälsningar Krezz =)

Dec 10, 2010 at 7:24 AM
Edited Dec 10, 2010 at 7:25 AM
burningice wrote:

DataFacade.GetData<T>().FirstOrDefault(t => t.PageId == PageRenderer.CurrentPageId);

Where T is the type of your meta data


It is better to use the public API whan accessing data and page related stuff. The public API will never change in future releases of C1, DataFacade and other non-public API classes might change. The code should be something like this:


using (DataConnection connection = new DataConnection())
   connection.Get<T>().FirstOrDefault(f => f.PageId == connection.SiteNavigator.CurrentPageId);


Dec 10, 2010 at 7:47 AM

Maybe you should mark the non-public API's as internal instead of public then

Dec 10, 2010 at 7:56 AM

Makes very good sense and we would like to do it. But the API was made a little late in the process and that gives us a lot of legacy code (ex. in existing packages and sites) that still uses the DataFacade. So until all these old references to DataFacade is fixed we are stuck with public and not internal. Unfortunately! Keeping it public is the friendly way for those that already used it before C1 2.0. But we might be more explicit about this.

Dec 13, 2010 at 10:09 PM

You should also update you sample pages shows how to access data with DataFacade.GetData<>


Dec 14, 2010 at 1:24 PM

Tnx @burningice - we fix it and spend some time looking through other samples and ensure that they are ut-to-date with the current release.

Dec 14, 2010 at 10:23 PM

Nagging you with my questions =)

If using the Visual Functions option how to format a "a href" link using the PageId as a part of the string?

I have succeded to do it in the XSLT Functions area but I would like to make a list of objects with a link for each object stored (pages stored with metadata). Shows the same object twice instead of showing the two individual objects.

Best Regards Krezz



Dec 15, 2010 at 8:35 AM
Edited Dec 15, 2010 at 8:37 AM

@Kewzz questions are why we have a forum, we are all here to help each other ;-)

You should go with XSLT or .NET/ASP.NET - Visual Functions isn't suited for more complex scenarios.

If you are experiencing that you get the wrong data (you can see this in the XSLT's Preview 'Input' section, you should probably look at your filter. If you get duplicate output you can again check your 'preview input' and see if it's data that duplicate or - if it does not - your XSLT code that do the duplication.

If you are new to XSLT in Composite C1 here is a good rule of thumb: First make sure that your 'Preview, Input' contain the data you need and preferably 'exactly' what you need - then focus on the XSLT and use the 'Preview, output' to ensure that you have the result you desire.

In situations like this where you work with page specific meta data, make sure you are familiar with the "debug" features available on the XSLT's Functions Settings tab - here you can select a page/language you want the preview/test data to relate to.