ability to add arbitrary content to head and body during client and server rendering

This commit is contained in:
sbwalker
2023-05-15 16:43:22 -04:00
parent 7f7dff7019
commit dbe7324c7f
6 changed files with 131 additions and 37 deletions

42
Oqtane.Client/Head.razor Normal file
View File

@ -0,0 +1,42 @@
@using System.ComponentModel
@using Oqtane.Shared
@inject SiteState SiteState
<title>@title</title>
@((MarkupString)content)
@code {
private string title = "";
private string content = "";
protected override void OnInitialized()
{
((INotifyPropertyChanged)SiteState.Properties).PropertyChanged += PropertyChanged;
}
private void PropertyChanged(object sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case "PageTitle":
if (title != SiteState.Properties.PageTitle)
{
title = SiteState.Properties.PageTitle;
StateHasChanged();
}
break;
case "HeadContent":
if (content != SiteState.Properties.HeadContent)
{
content = SiteState.Properties.HeadContent;
StateHasChanged();
}
break;
}
}
public void Dispose()
{
((INotifyPropertyChanged)SiteState.Properties).PropertyChanged -= PropertyChanged;
}
}