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.

weblog specific sidebar if

November 08, 2007 3:16pm

Subscribe [1]
  • #1 / Nov 08, 2007 3:16pm

    guerrilla

    31 posts

    I’m building a community site with 6 weblogs and a calendar weblog. To make anticipated changes in the standard design easier down the road, I’m using global templates for standard things like page_header, navigation, footer and the sidebar navigation. It’s working fine except for a quirk with the calendar weblog.

    I’d like to post recent entries f or each weblog in the sidebar. Again, this is working except, of course, for the calendar which doesn’t display future entries in the sidebar. Adding show future entries didn’t work, so I decided to simply list the recent entries from the general community weblog which requires and {if} statement that would set the weblog identity. Alas, this isn’t working. Here’s the standard code:

    . . .
        <h2 class="sidetitle">Most recent entries</h2>
        <ul>
        {exp:weblog:entries orderby="date" sort="desc" limit="15" weblog="{embed:weblog}"  dynamic="off" disable="pagination|custom_fields|categories|member_data|trackbacks"}
        <li><a href="http://{title_permalink={embed:template_group}/index}">{title}</a></li>
    {/exp:weblog:entries}
        </ul>
    .
    .
    .

    Here’s the test code I tried:

    <ul>
            {if {embed:weblog} == "calendar"}
            <li>WEBLOG IS ({embed:weblog})CALENDAR</LI></UL>
            {if:else}
            <LI CLASS="DATE"> ({embed:weblog}) not calendar </li>
            {/if}
            </ul>

    For some reason, even when the weblog is the “calendar” weblog, it always defaults to the {if:else} option.

    Here’s the site URL: http://drycreekcommunity.org/index.php/calendar/

    Any ideas of a quick solution and why the comparison is always returning FALSE?

    Thanks.

  • #2 / Nov 08, 2007 3:22pm

    Lisa Wess

    20502 posts

    Hi, guerilla, I’m a bit confused about the initial problem - why doesn’t show_future_entries work? Or that doesn’t matter now?

    In any case, in your test code, try outputting just {embed:weblog}.

    Also, where is your embed statement?  What does it look like?

  • #3 / Nov 08, 2007 3:46pm

    guerrilla

    31 posts

    Lisa, I don’t know why the show future entries didn’t work, but I don’t want to show future entries for the other weblogs so I’d have to use the conditional statement anyway.

    I am outputting the {embed:weblog} information in the test code and on the calendar page it very cheerily writes:

    (calendar) not calendar

    and everywhere else it very accurately reports that, for example, “(coalition) not calendar” or “(dcc) not calendar.” The correct weblog is being written.

    Test code:

    <h3>{embed:weblog}</h3>
    <p>        <ul><br />
            {if {embed:weblog} == "calendar"}<br />
            <li>WEBLOG IS ({embed:weblog})CALENDAR</LI></UL><br />
            {if:else}<br />
            <LI CLASS="DATE"> ({embed:weblog}) not calendar </li><br />
            {/if}<br />
            </ul>

    The embedding of the sidebar template looks like this in all weblogs:

    {embed="global_embeds/sidebar" weblog="{my_weblog}" template_group="{my_template_group}" }

    If just can’t seem to find a way to tell the embedded sidebar that if it’s the calendar blog either show recent future entries from the calendar weblog or show the recent entries from the general community weblog(s).

  • #4 / Nov 08, 2007 3:48pm

    Lisa Wess

    20502 posts

    What if you hard-code the weblog= instead of pulling in the assigned variable? so weblog=“whatever the weblog’s shortname is” =)

  • #5 / Nov 08, 2007 4:03pm

    guerrilla

    31 posts

    Uhm, I think you’re misunderstanding the concept. The idea is to make the code as portable as possible so I don’t have to go into a jillion templates (or even a dozen hopefully) every time I need to change the sidebar navigation.

    Yes, I *could* hardcode the sidebar in all of the calendar templates and leave the global embeds in the other sections/weblogs, but that would mean every time I had to modify the global sidebar, I’d have to go in an change each and every calendar template as well.

    Passing the weblog variable to the sidebar tags works fine. What’s not working is using a conditional statement to compare the weblog variable (which I as I understand it is the weblog short name) to the text.

    But I don’t understand why I can’t get the conditional to correctly compare the weblog variable to the text that matches it. Is there something EE adds when writing the short name of the weblogs?

  • #6 / Nov 08, 2007 4:25pm

    Lisa Wess

    20502 posts

    I understand the concept perfectly, however, we need to isolate down the issue to *just* the embeds.  So, if instead of using the assigned variable in your embed, and you hardcode the short name, then output {embed:weblog} in the target template, do you then get the appropriate value?  So, template 1:

    {embed="global_embeds/sidebar" weblog="weblog_short_name"}

    Then in global_embeds/sidebar, just output this:

    {embed:weblog}

    Now visit the original template, what do you get?

  • #7 / Nov 08, 2007 4:53pm

    guerrilla

    31 posts

    Lisa, I get the exact same results.

    If I hardcode the short name [calendar] into the calendar template where it calls the sidebar:

    {embed="global_embeds/sidebar" weblog="calendar" template_group="{my_template_group}" }

    it still produces:

    calendar

      * (calendar) not calendar

    in on the calendar pages, but still accurately displays the weblog short name and entries for the other weblogs. The embed is reading the my_weblog assigned variable just fine and is printing it out in the test code:

    <h3>{embed:weblog}</h3>

    I just can’t get it to accurately compare the short name [calendar] to the comparison text. I even tried it with a different weblog [dcc] and it still returns a False comparison. I.e., I changed the test code to read:

    <h3>{embed:weblog}</h3>
    <p>        <ul><br />
            {if {embed:weblog} == "dcc"}<br />
            <li>WEBLOG IS ({embed:weblog}) Home</LI></UL><br />
            {if:else}<br />
            <LI CLASS="DATE"> ({embed:weblog}) not home </li><br />
            {/if}<br />
            </ul>

    Not to confuse the issue (but I don’t get this myself), but I tried copying and pasting the test comparison into the calendar weblog index template and I still can’t compare the short name of the weblog to the text! I get exactly the same results as in the embedded global_template.

    Code in the index page template:

    <h3>{my_weblog}</h3>
    <p>        <ul><br />
            {if {my_weblog} == "calendar"}<br />
            <li>({my_weblog})  IS CALENDAR</LI></UL><br />
            {if:else}<br />
            <LI CLASS="DATE"> ({my_weblog}) not calendar </li><br />
            {/if}<br />
            </ul>

    There must be some other people using a conditional to determine which weblog they are in and then displaying different formatting. Is there some other test code I can try?

  • #8 / Nov 08, 2007 5:02pm

    Lisa Wess

    20502 posts

    Can you clarify this:

    it still produces:

    calendar

    * (calendar) not calendar

    Do you have a link to the template in question?  Are you testing this in two templates with * only* the embed code and nothing else?

    We need to find out what the embed is outputting, before we can use it in a conditional.  One step at a time. =)

  • #9 / Nov 08, 2007 5:21pm

    guerrilla

    31 posts

    Okay, Lisa, I’ve done some more testing. You’re right. One step at a time. The problem is not the embed. The problem is much more basic.

    In the index template, outside of any other tags or modules, I tested comparing the assigned weblog short name against another variable and then against a text comparison:

    {assign_variable:thisWeblog="calendar"}
    
            If I use the assigned_variable: thisWeblog,
    
            {if {my_weblog} == {thisWeblog}}
            <h3>({my_weblog})  THE COMPARISON WORKS!</h3>
    <p>        {if:else}<br />
            </p><h5> ({my_weblog}) the comparison does not work </h5>
    <p>        {/if}<br />
                        If I use "calendar",</p>
    
    <p>        {if {my_weblog} == "calendar"}<br />
            </p><h3>({my_weblog})  THE COMPARISON WORKS!</h3>
    <p>        {if:else}<br />
            </p><h5> ({my_weblog}) the comparison does not work </h5>
    <p>        {/if}

    The results were:

    If I use the assigned_variable: thisWeblog,
    (calendar) THE COMPARISON WORKS!

    If I use “calendar”,
    (calendar) the comparison does not work

    FYI, I copied the text “calendar” directly from the assigned variable my_weblog to make absolutely certain there was no difference between the two.

    Apparently, in EE, you have to compare two weblog variables when comparing weblog names? At least that’s how it seems to be working in the test.

    🐛

    here’s the URL: http://drycreekcommunity.org/index.php/calendar/

  • #10 / Nov 08, 2007 5:28pm

    guerrilla

    31 posts

    Lisa,

    Ah-hah! If you remove the quotes around the text, the comparison works on the index template test:

    {if {my_weblog} == calendar}
            <h3>({my_weblog})  THE COMPARISON WORKS!</h3>
    <p>        {if:else}<br />
            </p><h5> ({my_weblog}) the comparison does not work </h5>
    <p>        {/if}

    So I’m now going to do some testing without the quotes in the embedded template…

  • #11 / Nov 08, 2007 5:29pm

    Lisa Wess

    20502 posts

    Assigned variables are simple text replacements: they do not work in conditionals. You put them in the top of the template then just use them to echo that information multiple places in the template; but not for comparisons.

  • #12 / Nov 08, 2007 5:39pm

    guerrilla

    31 posts

    You’re right. Reversing the comparison test code gets the same results.

    Okay, so what would be some test code that we can use to print something on the page depending upon which weblog is reading the template?

  • #13 / Nov 08, 2007 5:40pm

    Lisa Wess

    20502 posts

    Weblogs don’t read templates; templates read weblogs…. =)

    Why don’t we back up a bit.  What is your actual goal? In plain english, no code.

  • #14 / Nov 08, 2007 5:59pm

    guerrilla

    31 posts

    I’ve now got two goals:

    1) Display some different text depending upon which weblog.

    2) As I mentioned, I want to either display future entries in the sidebar when the weblog is the calendar or display the recent entries for the community weblog in the sidebar when the weblog page is for the calendar weblog. In other words, when folks are looking at the (*expletive deleted*) calendar weblog/section, they aren’t looking at an empty (and obviously broken) “Recent Entries” side title—it either displays the upcoming calendar events Or it displays recent community posts Or it doesn’t display the side title “Recent Entries.”

    It seemed so simple when I started…

  • #15 / Nov 08, 2007 6:01pm

    Lisa Wess

    20502 posts

    Ok, how do YOU know what weblog is being displayed?  Is there a segment being used? a different template? Any other indicator?

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

ExpressionEngine News!

#eecms, #events, #releases