Ancestor field displaying instead of current page field - Umbraco v7.3.4
Hi,
I am using Umbraco v7.3.4 and something odd is happening after my upgrade from v7.2.8. I have an Umbraco field item in one of my templates and it works fine as long as there is something in the field. If the field is empty, it appears to be searching it's ancestors until it finds a value for that field and use that, instead of leaving the area blank.
to show the value of a field but default to another altField if it is blank...
you can make this recursive too, in fact to see all the options, if you go into the back office, and open up a macro partial, and press the little 'field button' you get a helpful form to build the syntax...
I found that I couldn't put it directly into the template unless I put in an Inline Razor Macro, I think that is because the site uses WebForms and not MVC.
I have changed my partial view the the following:
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@{
var pageField = Model.MacroParameters["pageField"].ToString();
var insertBeforeString = HttpUtility.HtmlDecode(Model.MacroParameters["insertBefore"].ToString());
var insertAfterString = HttpUtility.HtmlDecode(Model.MacroParameters["insertAfter"].ToString());
var altPageField = Model.MacroParameters["altPageField"].ToString();
@Umbraco.Field(pageField, altFieldAlias: altPageField, insertBefore: insertBeforeString, insertAfter: insertAfterString)
}
It's still a little funny that if I insert a page field normally and the page field is empty that goes up its ancestors until it finds a value.
Ancestor field displaying instead of current page field - Umbraco v7.3.4
Hi,
I am using Umbraco v7.3.4 and something odd is happening after my upgrade from v7.2.8. I have an Umbraco field item in one of my templates and it works fine as long as there is something in the field. If the field is empty, it appears to be searching it's ancestors until it finds a value for that field and use that, instead of leaving the area blank.
Here is the code in the template:
The field "relatedInformation" is a RichText Editor.
This is also happening for Textstring fields. Example code:
In this case I wanted to use the current page name unless alternatePageTitle had a value.
As a temporary solution I wrote the below partial view. If there is a better way to do this, please let me know.
Hi Ben
If I have understood this correctly, you are putting either the CurrentPage.Name or altPageName in an H1 tag ?
Or am I missing something?
Regards
Gary
Hi Gary,
Yes, I was trying to put either the altPageName or CurrentPage.Name inside an H1 tag.
Hi Ben
Inside a macro partial view you can use the syntax:
or
to show the value of a field but default to another altField if it is blank...
you can make this recursive too, in fact to see all the options, if you go into the back office, and open up a macro partial, and press the little 'field button' you get a helpful form to build the syntax...
Thanks Marc! I will try that out.
I found that I couldn't put it directly into the template unless I put in an Inline Razor Macro, I think that is because the site uses WebForms and not MVC.
I have changed my partial view the the following:
It's still a little funny that if I insert a page field normally and the page field is empty that goes up its ancestors until it finds a value.
Thanks for your help Marc.
is working on a reply...