Developer forum

Forum » Templates » RE: Check on Div tag, If Placeholder Empty, Razor

RE: Check on Div tag, If Placeholder Empty, Razor

Aditya Bante
Reply

Hi

The if statement is working fine I do not get any errors but It dosen’t do what it supposed to. It dosen’t out put anything even if the placeholder contains the paragraph ?  any thoughts why that might be ?    Thanks. 

@if (!string.IsNullOrEmpty(GetString("subpage-full-wrapper-2")))
              {
                <div class="subpage-full-wrapper-2 col-xs-12" style="background-color:@BackgroundMiddle;">
                    <div class="container">
                        <div id="subpage-full-2" class="dwcontent row" title="Fuld bredde midt"></div>
                    </div>
                </div>
              }
             

   


Replies

 
Thomas Schroll
Reply

Hi Aditya

Try @if(!string.IsNullOrEmpty(GetString("DwContent(subpage-full-2)"))){

instead.

Regards Thomas

 
Aditya Bante
Reply

Thanks Thomas 

but it's not working when i use this "@if (string.IsNullOrEmpty(GetString("DwContent(subpage-full-2)")))" it
display nothing even if there is a paragraph in this placeholder.

The thing is I have 3 placeholders and they have 3 different background colors and when the placeholder does not contain
anything it  still shows a background color of that placeholder. as you can see it in a attached file.

this is my page template 
<section id="content">           
    <div id="subpage" class="row">
                <div id="subpage-full-wrapper-1" class="col-xs-12" style="background-color:@BackgroundTop;">
                    <div class="container">
                        <div id="subpage-full-1" class="dwcontent row" title="Fuld bredde top"></div>
                    </div>
                </div>
              @if (string.IsNullOrEmpty(GetString("DwContent(subpage-full-2)")))
              {

                    <div class="subpage-full-wrapper-2 col-xs-12" style="background-color:@BackgroundMiddle;">
                        <div class="container">
                            <div id="subpage-full-2" class="dwcontent row" title="Fuld bredde midt"></div>
                        </div>
                    </div>
              }
                <div id="subpage-full-wrapper-3" class="col-xs-12" style="background-color:@BackgroundBottom;">
                    <div class="container">
                        <div id="subpage-full-3" class="dwcontent row" title="Fuld bredde bund"></div>
                    </div>
                </div>  
            
    </div>  
</section>

do you have any suggestions? 

 

Regards

Aditya Bante

 

WrapperBackground.png
 
Thomas Schroll
Reply
This post has been marked as an answer

Hi Aditya

Your if statement only shows the content if there is no content. You need to put a '!' before 'string' (show the content if it is NOT null or empty). If you still can't see the content, try inserting @TemplateTags() in your code. DW will then, frontend, show you your available tags. Check to see if you have the correct content placeholder names.

Regards Thomas

Votes for this answer: 1
 
Aditya Bante
Reply

Hi Thomas

I got these tags

DWContent(subpagefull1)
DWContent(subpagefull2)
DWContent(subpagefull3
)

and when I put the placeholder name without "-" in the razor code it's working fine. That's what I wanted.

@if (!string.IsNullOrEmpty(GetString("DwContent(subpage-full-2)"))) { }

Thank you so much for your help :)

Best Regards
Aditya Bante

 

You must be logged in to post in the forum