loyalflow
loyalflow

Reputation: 14879

How to hide a section with default content?

In my Master I have a section with default content:

@section BlahBlah {
  <p>Hello world!</p>
}

Now in my view pages, for some of them, I want to hide this section completely.

How can I do this?

Upvotes: 0

Views: 57

Answers (1)

Brandon
Brandon

Reputation: 69983

There is a built in function called IsSectionDefined that will let you default the content if the given section name hasn't been defined. You can see this blog post for more details.

@if(IsSectionDefined("BlahBlah")) {
    @RenderSection("BlahBlah")
} else {
    <p>Hello world!</p>
}

Upvotes: 3

Related Questions