SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2009
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Is there anything wrong with this statement

    I'm trying to widgetize a sidebar


    The example code is:
    PHP Code:
    <?php if (function_exists('dynamic_sidebar) || !dynamic_sidebar()) : ?>

         <li>Stuff shown here if widgets are not active</li>

    <?php endif; ?>
    Using this method, it works!

    I wanted to get a little creative and try something like this

    PHP Code:
    <?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar()) { ?>
         <li>Stuff shown here if widgets are not active</li>
    <?php } endif; ?>
    I keep geting Parse error!

    What is wrong with my second example?

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,032
    Mentioned
    152 Post(s)
    Tagged
    2 Thread(s)
    It's either

    if:
    // some code
    endif;

    OR

    if {
    // some code
    }

    not a combination thereof

    you have

    if {
    // some code
    } endif;
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2009
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ScallioXTX View Post
    It's either

    if:
    // some code
    endif;

    OR

    if {
    // some code
    }

    not a combination thereof

    you have

    if {
    // some code
    } endif;
    Thank you

    Sorry if this is a stupid question..

    I'm supposed to end the if statement right?

    So if i start an if statement like so:

    PHP Code:
    <?php if ( this statement is false ) { ?>
     // some code
    //reason i'm doing it like this is just to experiment
    <?php ?>
    How do i end the statement above?

    Thank you

  4. #4
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,032
    Mentioned
    152 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by webfreak05 View Post
    I'm supposed to end the if statement right?

    So if i start an if statement like so:

    PHP Code:
    <?php if ( this statement is false ) { ?>
     // some code
    //reason i'm doing it like this is just to experiment
    <?php ?>
    How do i end the statement above?

    Thank you
    You don't, it's already ended by the } in the last line

    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  5. #5
    SitePoint Enthusiast
    Join Date
    May 2010
    Location
    Netherlands
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by webfreak05 View Post
    Thank you

    Sorry if this is a stupid question..

    I'm supposed to end the if statement right?

    So if i start an if statement like so:

    PHP Code:
    <?php if ( this statement is false ) { ?>
     // some code
    //reason i'm doing it like this is just to experiment
    <?php ?>
    How do i end the statement above?

    Thank you
    Perhaps reading this and this makes things more clear.
    If-statements are either encapsulated by { and } or by 'if: ... endif;'.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •