Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Check if block content is empty

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
maspai
Smarty n00b


Joined: 02 May 2015
Posts: 4

PostPosted: Sat May 02, 2015 9:32 am    Post subject: Check if block content is empty Reply with quote

Layout:
Code:
<div id="container">{block "main"}{/block}</div>


View:
Code:
{block "main"}The content{/block}


How to hide div.container when content of block "main" is empty or not passed by view - other than using {capture} in place of {block}?

If I do in layout:
Code:
<div id="container">{block "main" hide}{/block}</div>

div.container will always be displayed.

Thanks.
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Sat May 02, 2015 9:39 pm    Post subject: Reply with quote

Full, working code, please.
From your description, it leaves much to guess, and i'm not into guesswork.
Back to top
View user's profile Send private message
maspai
Smarty n00b


Joined: 02 May 2015
Posts: 4

PostPosted: Sun May 03, 2015 4:49 am    Post subject: Reply with quote

I'm using Kohana framework.

My master layout:
Code:
<body><div id="container">{block "main"}{/block}</div></body>

My view (View 1) that extends master layout:
Code:
{block "main"}Some content{/block}

My another view (View 2) that also extends master layout, doesn't pass {block "main"}.

What I expect is:
    View 1 will have
    Code:
    <body><div id="container">Some content</div></body>
    View 2 will have only
    Code:
    <body></body>
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Sun May 03, 2015 6:23 am    Post subject: Reply with quote

Seems like you didn't read documentation.
http://www.smarty.net/docs/en/language.function.block.tpl {$smarty.block.child}
Back to top
View user's profile Send private message
maspai
Smarty n00b


Joined: 02 May 2015
Posts: 4

PostPosted: Sun May 03, 2015 2:54 pm    Post subject: Reply with quote

Thanks. I didn't read the whole page.
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sun May 03, 2015 11:42 pm    Post subject: Reply with quote

Master layout:
Code:
<body>{block "main" hide}<div id="container">{$smarty.block.child}</div>{/block}</body>
Back to top
View user's profile Send private message
maspai
Smarty n00b


Joined: 02 May 2015
Posts: 4

PostPosted: Mon May 04, 2015 3:50 am    Post subject: Reply with quote

U.Tews wrote:
Master layout:
Code:
<body>{block "main" hide}<div id="container">{$smarty.block.child}</div>{/block}</body>

This is better than mine. Before, I added {if} to check if {$smarty.block.child} is empty. Thanks.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP