0

I have a sub-application (YetAnotherForum.NET) living in a child directory of my Composite C1 site. In order to maintain a consistent look and feel I want to pull in C1 functions for the navigation elements.

Note: All html mark-up in code below has had pointy brackets replaced with square brackets in order to allow posting here.

I've figured out I can call C1 functions using this syntax:

[f:function ID="Function1" name="Custom.Layout.FooterLinks" runat="server"/]

However, the data behind the function seems to be unavailable. Any ideas what the data issue might be? Perhaps I need the external page to inherit from some form of Composite C1 page?

Here's the function code:

@using Composite.Data;
@using Composite.Data.Types;
@using Composite.Data.ProcessControlled.ProcessControllers.GenericPublishProcessController;

@using CompositeC1Contrib.RazorFunctions;

@inherits CompositeC1WebPage

@functions {
    private IEnumerable FooterLinkPages()
    {
        IEnumerable pages = DataFacade.GetData();
        IEnumerable returnPages;

        using (DataConnection connection = new DataConnection())
        {
            returnPages = (from l in connection.Get()
                           join p in pages on l.Page equals p.Id
                           where l.PublicationStatus == GenericPublishProcessController.Published
                            && p.PublicationStatus == GenericPublishProcessController.Published
                           orderby l.Position ascending
                           select p).ToList();
        }

        return returnPages;
    }
}

[ul class="unstyled"]
@foreach (IPage page in FooterLinkPages())
{
    [li]@(String.IsNullOrWhiteSpace(page.MenuTitle) ? page.Title : page.MenuTitle)[/a][/li]
}
[/ul]
Gavin
  • 5,629
  • 7
  • 44
  • 86
  • BTW: I'm aware of this article - http://docs.composite.net/FAQ/Developer?q=How+to+integrate+YetAnotherForum+with+C1%3F - it's just a bit out-of-date for both YAF and C1. – Gavin Jul 04 '12 at 08:37
  • Note sure if this is it, but if you experience problems getting at data from an external source this could be related to http://docs.composite.net/Data/DataFAQ?q=What+does+%22ThreadDataManager+hasn%27t+been+initialized...%22+exception+mean%3F – mawtex Jul 04 '12 at 22:04
  • Cheers mawtex - almost! Just needed a DataScope as well else data would sometimes be there / sometimes not (mainly not) ;) – Gavin Jul 05 '12 at 05:12

1 Answers1

1

You need to wrap the data access code in:

using(Composite.Core.Threading.ThreadDataManager.EnsureInitialize())
{
    using (DataScope localeScope = new DataScope(new System.Globalization.CultureInfo("en-NZ")))
    {
        ...
    }
}
Gavin
  • 5,629
  • 7
  • 44
  • 86