c# - Umbraco 7 - Get property from one page to another -
im new umbraco 7
i have masterpage - inside have 2 partialviews - header
& footer
i have 2 subpages inherites masterpage - home page
& standard page
inside home page - document type
have reletad links
property
the code releted links
property inside partialview called links
@inherits umbraco.web.mvc.umbracotemplatepage @using newtonsoft.json.linq @{ if (model.content.hasvalue("externallinks") && model.content.getpropertyvalue<string>("externallinks").length > 2) { <ul> @foreach (var item in model.content.getpropertyvalue<jarray>("externallinks")) { var linktarget = item.value<bool>("newwindow") ? "_blank" : null; if (model.content.getpropertyvalue<jarray>("externallinks").first() == item) { <li> <a href="@(item.value<string>("link"))" target="@linktarget"> <i class="fa fa-phone" aria-hidden="true"></i> @(item.value<string>("caption"))</a> </li> } else { <li> <a href="@(item.value<string>("link"))" target="@linktarget"> <i class="fa fa-flag" aria-hidden="true"></i> @(item.value<string>("caption"))</a> </li> } } </ul> } }
the links
partialview loaded inside header
partialview
the code working fine when navigating home page
if go standard page
reletad links
property no loger visible.
what can fix this.
instead of referencing current page (through model.content) you'll want reference homepage
i've added bit of code partialview illustrate it, haven't tested though
@inherits umbraco.web.mvc.umbracotemplatepage @using newtonsoft.json.linq @{ // first homepage traversing umbraco tree , searching homepage node var homepage = umbraco.typedcontentatroot().first().descendantsorself().firstordefault(x => x.documenttypealias == "home"); if (homepage != null && homepage.hasvalue("externallinks") && homepage.getpropertyvalue<string>("externallinks").length > 2) { <ul> @{ var externallinks = homepage.getpropertyvalue<jarray>("externallinks"); foreach (var item in externallinks) { var linktarget = item.value<bool>("newwindow") ? "_blank" : null; if (externallinks.first() == item) { <li> <a href="@(item.value<string>("link"))" target="@linktarget"> <i class="fa fa-phone" aria-hidden="true"></i> @(item.value<string>("caption"))</a> </li> } else { <li> <a href="@(item.value<string>("link"))" target="@linktarget"> <i class="fa fa-flag" aria-hidden="true"></i> @(item.value<string>("caption"))</a> </li> } } } </ul> } }
Comments
Post a Comment