Copied to clipboard

Flag this post as spam?

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


  • Phil Veloso 38 posts 251 karma points
    Jun 25, 2019 @ 14:57
    Phil Veloso
    0

    Custom theme - How to get page id

    Hello,

    I'm in the process of writing a custom theme for my email templates and want to access content from the submitted page via TypedContent, but struggling to pass in the node ID?

    Can someone please point me in the right direction?

    Many thanks, Phil

  • Lewis Logan 21 posts 132 karma points
    Jun 25, 2019 @ 15:33
    Lewis Logan
    0

    Hi Phil,

    I would suggest looking into a custom field type. A guide can be found here:

    https://our.umbraco.com/documentation/Add-ons/umbracoforms/developer/extending/adding-a-fieldtype

    I've used this to create a hidden field, have the field value set to the name of the page the form is on and then have this come through on the email that is sent out. You could similarly use this to get the node ID into the template.

    Kind Regards, Lewis

  • Phil Veloso 38 posts 251 karma points
    Jul 17, 2019 @ 23:14
    Phil Veloso
    100

    Thanks Lewis,

    In the end I used a hidden field with a magic string for node ID to get the IPublishedContent.

    var nodeId = "0";
    foreach (var field in Model.Fields)
    {
        if ( field.Alias == "nodeId" )
        {
            var id = field.GetValue();
            nodeId = id.ToString();
        }
    }
    var node = nodeId != "0" ? Umbraco.TypedContent(nodeId) : null ;
    
Please Sign in or register to post replies

Write your reply to:

Draft