You need to create a custom token to achieve it. Create a custom Token processor inheriting ExpandInitialFieldValueProcessor
with the following code. It checks if the value of the field contains the $ancestortitle
token. If it does it checks if the parent is not null. If the parent is not null and there are parent of parent item the value is set to the field.
using Sitecore.Pipelines.ExpandInitialFieldValue;
public class TokenAncestorTitleProcessor : ExpandInitialFieldValueProcessor
{
public override void Process(ExpandInitialFieldValueArgs args)
{
if (args.SourceField.Value.Contains("$ancestortitle"))
{
if (args.TargetItem != null && args.TargetItem.Parent != null && args.TargetItem.Parent.Parent != null)
{
//Replace any specific filed value like here used Title from parent item
args.Result = args.Result.Replace("$ancestortitle", args.TargetItem.Parent.Parent.Fields["Title"].Value);
// If you want to replace Name of the parent then uncomment below line and comment above one.
//args.Result = args.Result.Replace("$ancestortitle", args.TargetItem.Parent.Parent.Name);
}
}
}
}
Config change
<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<pipelines>
<expandInitialFieldValue>
<processor resolve="true" type="MyAssembly.MyNamespace.TokenAncestorTitleProcessor, MyAssembly" patch:after="processor[@type='type=Sitecore.Pipelines.ExpandInitialFieldValue.ReplaceVariables, Sitecore.Kernel']"/>
</expandInitialFieldValue>
</pipelines>
</sitecore>
</configuration>
Template configuration:

Hope it helps!