Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • JohnAss 18 posts 128 karma points
    May 23, 2017 @ 17:19
    JohnAss
    0

    Access header/footer content on ftProduct

    I made two partials (footer and header) which I want to render on all pages.

    I have added FastTrack to my site by following the "Integrating Merchello Into An Existing Website" video.

    They way I get content on a partial is like they do in the umbraco template:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
        var homePage = CurrentPage.AncestorsOrSelf(1).First();
    }
    
    <img src="@homePage.logo" class="img-responsive headerImage" />
    

    The content from my partials work on all other FastTrack views but not the ftProduct

    How do I make ftProduct able to get that content?

  • Tom Steer 161 posts 596 karma points
    May 23, 2017 @ 18:48
    Tom Steer
    0

    Hey Jonas,

    This is because the product page is just a virtual node in Merchello so it doesn't sit within your sites content tree, so in theory doesn't have an ancestor.

    I haven't tried this myself but I think if you associate a node from within your Umbraco content tree as a parent node on the virtual product node, then you should be able to use things like AncestorsOrSelf like your doing within your header. You can do this by hooking into an event on the ProductContentFactory

    protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
    {
        ProductContentFactory.Initializing += ProductContentFactoryOnInitializing;
    }
    private static void ProductContentFactoryOnInitializing(ProductContentFactory sender, VirtualContentEventArgs e)
    {
        e.Parent = [Your root node];
    }
    

    Let me know if this works for you :)

    Cheers, Tom

  • JohnAss 18 posts 128 karma points
    May 23, 2017 @ 19:24
    JohnAss
    0

    Hi Tom,

    Im totally new to umbraco and merchello so this might be a stupid question.

    Where is the ProductContentFactory located?

    I dont seem to have the ProductContentFactory anywhere in my Solution when I search for it and I cant find anything about it on https://merchello.readme.io/

  • Tom Steer 161 posts 596 karma points
    May 23, 2017 @ 19:31
    Tom Steer
    0

    Hey Jonas,

    It's located in the Merchello.Web.Models.VirtualContent namespace. Although I've just had a look and it looks like the FastTrack starterkit already does this: https://github.com/Merchello/Merchello/blob/f3dd636fb3449d58d82ecd178b2ce9b1093c9615/src/Merchello.FastTrack.Ui/UmbracoEventHandler.cs#L115 so that might mean setting the parent doesn't mean those methods work start to work :( Maybe set a breakpoint in your product view and double check the Parent property isn't null.

  • JohnAss 18 posts 128 karma points
    May 23, 2017 @ 21:08
    JohnAss
    0

    Yea to me it would seem like something they already thought of.

    I would still like to try your suggestion out though, Im just having trouble understanding umbraco/merchello.

    The way I installed merchello was to go to Umbraco > Developer > Packages > Install local

    And here I uploaded the Merchello 2.5.0.zip which I got from: https://our.umbraco.org/projects/collaboration/merchello/

    I have looked everywhere and I dont have the ProductContentFactory.cs file.

    When I look at https://github.com/Merchello/Merchello/ I can see it has the file in src\Merchello.Web\Models\VirtualContent

    Shouldn't I have the whole "src" folder + files in my project as well?

  • Tom Steer 161 posts 596 karma points
    May 24, 2017 @ 07:19
    Tom Steer
    0

    The ProductContentFactory is just the class which exposes the event. You need to create your own class which inherits from Umbraco's ApplicationEventHandler and then override the ApplicationStarting method and hook up your event handler as shown in my previous comment

    https://our.umbraco.org/documentation/reference/events/Application-Startup

    https://our.umbraco.org/documentation/getting-started/Code/Subscribing-To-Events/

    Cheers,

    Tom

Please Sign in or register to post replies

Write your reply to:

Draft