Skip to content

Keeping references between pages to track dependencies of content

Simon Yohannes edited this page Feb 13, 2020 · 7 revisions

By default, Puck tracks references in your content to other content by processing any List<PuckReference> properties (i.e. Content Picker or Image Picker properties) with a property Transformer. you can find out if a page is referenced by another by going to the edit page in the backoffice for any given content and checking the References field on the default tab.

so while references for Content Pickers and Image Pickers are kept by default, for string fields like a Rich Text Editor you will need to opt in by decorating your properties/ViewModels with a StringReferencesTransformer attribute. here's an example:

[StringReferencesTransformer(Properties = new string[] { nameof(Homepage.MainContent),nameof(Homepage.IntroParagraph) })]
    public class Homepage:Page
    {
        [Required]
        [UIHint(EditorTemplates.RichTextEditor)]
        [Display(Name="Main Content",GroupName ="Content")]
        [IndexSettings(FieldIndexSetting = Field.Index.ANALYZED, Analyzer = typeof(SnowballAnalyzer))]
        public string MainContent { get; set; }

        [UIHint(EditorTemplates.RichTextEditor)]
        [Display(Name="Intro Paragraph",GroupName ="Content")]
        public string IntroParagraph { get; set; }
    }

in this example, the Transformer is on the ViewModel but you could just as well decorate a property with the attribute. the Properties field is set to specify which properties should be processed.

StringReferencesTransformer will store references to other pages and even images, whether they're local images or stored in azure and whether or not they're cropped or resized. for image support you will need to be uploading your images using the ImageVM ViewModel, which is already in your ViewModels folder by default and which i recommend keeping around not only for this functionality but also because the Image Picker editor template allows you to select images stored on ImageVM ViewModels.