ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

looooong code, simple solution?

December 12, 2008 7:01am

Subscribe [3]
  • #1 / Dec 12, 2008 7:01am

    Beertastic

    49 posts

    I’ve got many conditionals in a page.
    Basically I’ve a ‘sites’ template, that lists all my clients sites.
    Then I’ve several subsections that I have to place AFTER the site name.. so I can’t just create new templates for each section.
    eg:
    http://www.site.com/sites/sitename/news/blog_article_name/

    Anyhoo, all works great, until I try and pull in all relevent blog posts to that site.
    on it’s own, the blog retrieval code works great.. get’s the right blog based on segment_4 in the URL. But in this page, even thoguh I can see segment_4 where ever I choose to echo it, I keep getting the ‘no results’ text… the blog IS there… but this code doesn’t pick it up…. :-(

    On line 55, I’ve killed the

    {/exp:weblog:entries}

    to clear all processing before starting it again, AFTER I’ve done my blog lookup.

    I’ve asked a question based around this before, but I couldn’t figure it out..
    so here is my full code and full problem.. I’m hoping someone can help!

    {embed="home/header"}
    
    {if segment_2}
    
        {exp:weblog:entries weblog="sites"}
            <style>
                #mainArea  {
                top: 40px;
                }
            </style>
    
    
        <?php $siteMaster = "{url_title}"; ?>
        <div id="pageTitleText">{brandTitle}</div>
        <div id="siteNavLinks">
            <a{if segment_1 == "sites" AND segment_2 != "" AND segment_3 == ""} class="current"{/if} href="{homepage}/sites/{url_title}/">About</a>    
            {reverse_related_entries weblog="hearstblog" limit="1"}
                {if total_results > 0}
                    <a{if segment_3 == "news"} class="current"{/if} href="{homepage}/sites/<?=$siteMaster ?>/news/">Blog articles</a>    
                {/if}
            {/reverse_related_entries}
            <a{if segment_3 == "specs"} class="current"{/if} href="{homepage}/sites/{url_title}/specs/">Site Specifications</a>    
            <a{if segment_3 == "contact"} class="current"{/if} href="{homepage}/sites/{url_title}/contact/">Contact</a>
        </div>
    
        <div id="mainArea">
    
            {if segment_3 == 'news'}
                <div id="standardLayoutBlogLeft">
            {if:else}
                <div id="standardLayoutLarge">
            {/if}
    
            {if segment_3 == ''}
    
                <div id="standardLayoutLargeSites">
                    <div id="siteInformation">
                        <div id="siteDescription">{brandDescription}</div>
                        <div id="siteProfile">{if brandProfile} <strong>Reader Profile</strong> {brandProfile} {/if}</div>
                    </div>
                    <div id="siteImage">{brandImage}</div>
                </div>
    
            {if:elseif segment_3 == 'contact'}
                {brandContact}
                <hr ><a href="http://{homepage}/sites/{url_title}/">< < Back to {brandTitle}</a>
            </div>
    
            {if:elseif segment_3 == 'specs'}
                {brandSiteSpecs}
                <hr ><a href="http://{homepage}/sites/{url_title}/">< < Back to {brandTitle}</a>
            </div>
    
            {if:elseif segment_3 == 'news'}
            {/exp:weblog:entries}
                {if segment_4}
                    
                    {exp:weblog:entries weblog="hearstblog" url_title="{segment_4}"} 
                        {if no_results}
                            <div id="blogHeader">There are no blog entries selected - {segment_4}</div>
                        {/if}
                        <div id="blogHeader">{title}</div> - {segment_4}
    
                        <div id="blogDetails">Posted by {author} on {entry_date format="%j %M %Y"} (<a href="http://{homepage}/sites/{segment_2}/news/{url_title}/">{comment_total} comments</a>)</div>
                            {blogBody}
                        <hr >
                        <div id="blogCommentsCountBox">{comment_total} comments</div>
                    {/exp:weblog:entries}
    
                {if:else}
                    {exp:weblog:entries weblog="sites"}
                        {reverse_related_entries weblog="hearstblog"}
                            {if no_results}
                                <div id="blogHeader">There are no blog entries selected</div>
                            {/if}
                            <div id="blogHeader"><a href="http://{homepage}/sites/&lt?=$siteMaster">{title}</a></div>
    
                            <div id="blogDetails">Posted by {author} on {entry_date format="%j %M %Y"} (<a href="http://{homepage}/blog/article/{url_title}/">{comment_total} comments</a>)</div>
                            
    
                            {blogSummary}
                        {/reverse_related_entries}
                    {/exp:weblog:entries}
                    
                {/if}
                </div>
                    {embed="blog/rightHandMenu"}
            {/if}
    
            </div>
    
    {if:else}
    
    <div id="pageTitleText">Our Sites</div>
    <div id="mainArea">Get generic SITE list</div>
    {/if}
    
    {embed="home/footer"}
  • #2 / Dec 12, 2008 7:09am

    Beertastic

    49 posts

    Ok, REALLY sorry for the next bit, but it’s crazy, I had to share..

    I added:
    url_title=”{segment_4}”

    to exp:comment:entries AND exp:comment:form

    Now I see the ‘no results’ message but Do see the comments and the for for teh correct blog?????

    So it seems that just the entries tag is not working… but all the code ssms fine to me… :-(

    P.S… I hate Fridays…!! ;-p

  • #3 / Dec 12, 2008 12:10pm

    PhireGuys

    525 posts

    Yeah… a lot of code to look at but just so you know, EE doesn’t handle nested IFs properly.  It also doesn’t handle nested weblog:entries tags properly.  Sometimes it might work, sometimes it might not.

    What I’d suggest, and what I’ve done in the past, is to call an embed and feed over the variables.  This way, you’re only nesting embeds instead of more IFs or weblog:entries tags.

    Try breaking your code apart into multiple templates.  I usually create a separate template group just for these types of includes so my site doesn’t get cluttered.

    Hope that helps, sorry I can’t look at your code and really see what’s up.

  • #4 / Dec 12, 2008 12:19pm

    Beertastic

    49 posts

    Ah, good to know…
    I can’t have several templates, as the client wants the site name in the URL.. so I need 3 or 4 or even 5 levels of URL naming…

    Plus the client name has to be segemnt_2.. and they are dynamic from the DB..
    So I’m stuffed it seems ;-p

    Sigh.. I’ll keep thinking…

    Cheers for your input though!

  • #5 / Dec 12, 2008 12:27pm

    Ingmar

    29245 posts

    Actually, nesting {if}s is fine with advanced conditionals, but nesting other EE tags, most notable weblog:entries is generally not.

  • #6 / Dec 12, 2008 12:28pm

    PhireGuys

    525 posts

    Sure you can, because you’ll still be using the above template as the main one.  The rest will just be embedded based off of your criteria.

    But anyway I looked more into your code and you’re not embedding any weblog:entries tags.  So it’s just your IF statements that are most likely throwing things off.  Try using PHP as your method of determining your conditionals.  You can pull the segment_# info even if PHP is set to INPUT.

    I may be off on my suggestion because I’m not 100% clear what is and what isn’t working in your code.

  • #7 / Dec 12, 2008 12:31pm

    PhireGuys

    525 posts

    Actually, nesting {if}s is fine with advanced conditionals, but nesting other EE tags, most notable weblog:entries is generally not.

    Interesting, I’ve had nested IF’s not work for me.  Maybe it is the difference between “Advanced Conditionals” and something else?  Not really sure what that means.

  • #8 / Dec 12, 2008 12:34pm

    Ingmar

    29245 posts

    What that means is easily: {if foo == "bar} is a “simple” conditional. If you are using elseif or else, these are automatically “advanced” conditionals:

    Simple:

    {if foo == ""} ... {/if}
    {if foo != ""} ... {/if}

    Advanced:

    {if foo == ""} ... {if:else} ... {/if}

    Makes sense?

  • #9 / Dec 12, 2008 12:43pm

    PhireGuys

    525 posts

    Yeah I see.

    So then technically this would work?

    {if "blah" == "blah"}
    
         {if "john" = "bob"}
              hello
         {if:else}
              Bye
         {/if}
    
    {if:else}
         Yo!
    {/if}

    But this wouldn’t?

    {if "blah" == "blah"}
    
         {if "john" = "bob"}
              hello
         {if:else}
              Bye
         {/if}
    
    {/if}

    Sorry to hijack the thread, but this is a discovery to me 😊

  • #10 / Dec 12, 2008 12:46pm

    Ingmar

    29245 posts

    No, they should both work, although you’ll need a double equal sign in there.

  • #11 / Dec 12, 2008 12:53pm

    PhireGuys

    525 posts

    Alright I stand corrected.  Now I’m curious to go back to see how/why I encountered problems in the past.  It must have been something else I was doing wrong.

    Anyway, back to Beertastic.

  • #12 / Dec 12, 2008 2:31pm

    Beertastic

    49 posts

    Tis good to learn! on a Friday no less! ;-p

    Anyhoo, I’ve decided that I can’t do what I want…
    so I’m gonna do it with an Ajax call…
    Once my site is up, I’ll send a link and go over how I solved the prob.. I’d hate for anyone else to have to go through what I have today! ;-p

    Laters peeps.. good weekend…

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases