Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Steve 472 posts 1216 karma points
    Feb 07, 2013 @ 15:08
    Steve
    0

    Link back to the parent node

    I have a razor script that is creating links back to the parent page unless it doesn't have the property "CourseCatalogInternal" in which it is to just output the node name. Problem with my else statments though they are displaying the link then the following else statement printed out. What is wrong with my syntax?

     

    @{
    
    var page = Model.Parent;
    
        
    @if (page.IsNull("CourseCatalogInternal")) { @Node.Name } else { @page.pageTitle } else { @page.Name }
    }
  • Steve 472 posts 1216 karma points
    Feb 07, 2013 @ 15:13
    Steve
    0

    Sorry,

    The code posted incorrectly and it would not let me edit or delete it. So here is my code again.

    @{
    
    var page = Model.Parent;
    
        <div class="section-title">
        @if (page.IsNull("CourseCatalogInternal")) {
        <a href="@Node.Url;">@Node.Name</a>
        } else {
        <a href="@page.Url">@page.pageTitle</a>
        } else {
        <a href="@page.Url">@page.Name</a>
        } 
        </div>
    
    }
  • Steve 472 posts 1216 karma points
    Feb 07, 2013 @ 16:03
    Steve
    0

    Part of the problem is that the document type alias of "CourseCatalogInternal" in the first @if is never recognized even though it is the exact alias for that DocType. What's up?

  • gary 385 posts 916 karma points
    Feb 07, 2013 @ 16:04
    gary
    0
    <a href="@Node.Url;">@Node.Name</a>
    Think you have a stray semi-colon?
    Looks like its taking out of code
    G
  • Steve 472 posts 1216 karma points
    Feb 07, 2013 @ 16:10
    Steve
    0

    Thanks overlooked that. Now I need the first @if statement to work. Do I not understant .HasProperty ? Shouldn't I be able to put the doctype page alias in as .HasProperty ("CourseCatalogHome") ?

  • Steve 472 posts 1216 karma points
    Feb 07, 2013 @ 16:20
    Steve
    0

    Well, I got it working. It's not gracefull though. Aparently there is not a way to target the doc type alias so I targeted a property of the parent page of the top most node of this section I am working on. Surely there is a way to target the @Model DocTypeAlias ?

  • gary 385 posts 916 karma points
    Feb 07, 2013 @ 16:22
    gary
    0

    Hmm

    Think you might get away with @if (page (!="CourseCatalogInternal")) , it is something similar if not exactly this.

    could be page without the second brackets

    G

  • Steve 472 posts 1216 karma points
    Feb 07, 2013 @ 17:30
    Steve
    0

    I am now trying to check for the doc type alias of "CourseCatalogHome" and then assign it it's node name with a link.

    I've tried

    @if (Model("CourseCatalogHome")) {

    @if (Model.CourseCatalogHome) {

     

    This worked! Thanks for your suggestions!

    @if (Model.Where("nodeTypeAlias == \"CourseCatalogHome\"")) {

  • gary 385 posts 916 karma points
    Feb 07, 2013 @ 17:39
    gary
    0

    Hi Steve

    Hope you have it sorted by now, but just for completeness in case anyone is looking for the same answer, this worked for me ;

    @foreach (var item in parent.Children.Where("NodeTypeAlias != \"YourDocTypeAlias\""))    != giving the not

    so should give an alternative.

    As Im writing just seen your reply so,

    @if (Model.NodeTypeAlias == "CourseCatalogHome") {}

    Should return what you require - another really good way of traversing is in the razor walkthrough, if you want to return to a parent, @Model.Up().NiceUrl will give you a return to the parent in any child page, think that was in about razor walkthrough 7, in an old blog post. (NiceUrl if you are using or Url if not)

    Hope it helps

    G

Please Sign in or register to post replies

Write your reply to:

Draft