Copied to clipboard

Flag this post as spam?

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


  • Keith 74 posts 240 karma points
    Dec 18, 2023 @ 09:46
    Keith
    0

    Adding a template to existing document type still gives a 404

    Hi

    My site is running Umbraco 10.7. I have quite a few nodes that do not have a templete. This is because up until now, the didnt actually have pages on the site, they were just used as related content in pickers and things.

    But now we have decided that each of these nodes should have its own page, so i have added a default template to the document type.

    However, they only appear on the frontend when i click the green "Save and Publish" button on each node. If I call SaveAndPublish from the content service, they dont appear (i still get a 404). A successful publish event appears in the history for that node, so the SaveAndPublish is doing the publish, but something else is not happening (cache maybe?) when i call SaveAndPublish vs clicking the button.

    There are too many of these nodes for someone to manually click the green button on each. I need to do this programatically. Is there something I am missing? Is there a way of doing this?

    Many thanks

  • Keith 74 posts 240 karma points
    Dec 18, 2023 @ 10:27
    Keith
    0

    Ah OK.

    I was essentially doing this:

                    var existingContent = contentService.GetById(id);
                    contentService.SaveAndPublish(existingContent);
    

    But it seems the "default template" does not apply by default on the server.

    The client side posts a templateAlias value as part of the Save and Publish action.

    So now im doing something like this and it seems to be working:

     var existingContent = contentService.GetById(id);
     var contentType = contentTypeService.Get(existingContent.ContentType.Id);
     existingContent.TemplateId = contentType.DefaultTemplate.Id;
     contentService.SaveAndPublish(existingContent);                    
    
Please Sign in or register to post replies

Write your reply to:

Draft