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.

Nested exp:weblog:entries inside one another

March 23, 2009 12:09pm

Subscribe [4]
  • #1 / Mar 23, 2009 12:09pm

    k00k

    21 posts

    Is it ok to put {exp:weblog:entries} tags inside of other {exp:weblog:entries} tags?

    I have a conditional which checks to see if a field in the current entry is set to Yes or No. if set to No, it shows a couple fields from the current entry, if set to anything but No (Yes) then it should display a specific entry (default_sidebar). It works fine on my site’s index page, but not within a different section/weblog. No idea why it’s working in one place and not another. I also tried putting a closing {/exp:weblog:entries} tag immediately after {if:else} (which it should need I assume), but it only echoed that closing tag to the screen.

    Here’s the code:

    <div id="contentwrapper">
            <div id="col1">
                <span class="toppad"> </span>
                {exp:weblog:entries weblog="{my_weblog}" orderby="date" sort="desc" limit="1"}
                    <h2>{title}</h2>
    <p>                <span class="toppad"> </span><br />
                    {body}<br />
                    {extended}<br />
                    <span class="toppad"> </span><br />
            </div><br />
            <div id="col2"><br />
                <span class="center"><br />
                    {if default_sidebar == 'No'}<br />
                            {sidetitle}<br />
                            {sidecontent}<br />
                        {/exp:weblog:entries}<br />
                    {if:else}<br />
                        {exp:weblog:entries weblog="sidebar" entry_id="40"}<br />
                            {sidetitle}<br />
                            {sidecontent}<br />
                        {/exp:weblog:entries}<br />
                    {/if}<br />
                </span><br />
            </div><br />
        </div>


    Any ideas are appreciated.
    -steve

  • #2 / Mar 23, 2009 12:22pm

    Steve Abraham

    149 posts

    Hi Steve,

    This is just quick untested code, but try this and see how you get on:

    {exp:weblog:entries weblog="{my_weblog}" orderby="date" sort="desc" limit="1"}
    <div id="contentwrapper">
            <div id="col1">
                <span class="toppad"> </span>
                    <h2>{title}</h2>
    <p>                <span class="toppad"> </span><br />
                    {body}<br />
                    {extended}<br />
                    <span class="toppad"> </span><br />
            </div><br />
            <div id="col2"><br />
                <span class="center"><br />
                    {if default_sidebar == 'No'}<br />
                            {sidetitle}<br />
                            {sidecontent}<br />
                    {if:else}<br />
                        {embed="TEMPLATE_GROUP/defaultsidebar"}<br />
                    {/if}<br />
                </span><br />
            </div><br />
        </div><br />
    {/exp:weblog:entries}

    (obviously replace TEMPLATE_GROUP with the name of your template group)

    Then create a defaultsidebar template with this:

    {exp:weblog:entries weblog="sidebar" entry_id="40"}
    {sidetitle}
    {sidecontent}
    {/exp:weblog:entries}

    Good luck,
    Steve.

  • #3 / Mar 23, 2009 12:24pm

    Steve Abraham

    149 posts

    Sorry, just to answer your question - no, you can’t stack entry tags, thus the suggested code above. 😊

  • #4 / Mar 23, 2009 12:27pm

    Sue Crocker

    26054 posts

    Thanks for the assist, Steve.

    Don’t forget to use disable parameters as needed.

  • #5 / Mar 23, 2009 2:51pm

    k00k

    21 posts

    Hiya Steve,

    Thanks for the info, I’m thinking that if one cannot nest {exp:weblog:entries} tags, your solution shouldn’t work either as there will indeed still be a nested entries tag. However, to be thorough, I tried your solution to the letter and as I expected, the embed isn’t embedding. I can visit the embed directly via its url and all looks good. My conditional is executing properly as I put test comments in each case and they appeared appropriately when tested. Also put another {embed} that only contains plain text inside the else statement and it appeared properly.

    Just checked, and like my original, your solution (embed) works fine on my site’s homepage (http://domain.com/). Is it some kind of pathing problem when on subpages/weblogs (example: http://domain.com/index.php/company/about_us) ?

    I should note that my header and footer embeds are working fine on subpages.

    Puzzling…

  • #6 / Mar 23, 2009 3:34pm

    Steve Abraham

    149 posts

    Hi Steve,

    The embed method is the accepted method for nesting entries tags when you have to - it does definitely work, this must be some other issue that’s not obvious.

    I’m a very hands-on trouble shooter, and I find it very difficult to diagnose these problems without being able to tinker about with the code.  Would you be willing to PM me a URL so I can see the public side of it to compare to your code?

    Cheers!
    Steve.

  • #7 / Mar 23, 2009 3:36pm

    Ingmar

    29245 posts

    k00k, does that answer your initial question? If so, I’d suggest to mark this thread as resolved, or move it to Howto if you want me to.

  • #8 / Mar 23, 2009 3:46pm

    k00k

    21 posts

    Steve, sent you a PM.

    Ingmar, would probably make sense to leave it open for a short bit so I can post a solution when it’s figured out, yes?

    Thanks,
    -steve

  • #9 / Mar 23, 2009 3:48pm

    Ingmar

    29245 posts

    Sure. Just let me move it over to Howto, as it’s no longer “Tech Support” in the strictest sense… you can discuss it there all you want, no problem.

  • #10 / Mar 23, 2009 4:00pm

    Steve Abraham

    149 posts

    Hi Steve,

    Very first thing to try - add dynamic=“off” to your entries tags - so something like this:

    {exp:weblog:entries weblog="{my_weblog}" orderby="date" sort="desc" limit="1" dynamic="off"}

    Do this in the embed as well.  Test that before going any further.  If no luck, I’ve got a few questions…

    What template group & template name have you used for the sidebar embed?

    Can you show me the code you’ve used on your index page and on the about us page to embed the sidebar?

    Cheers! :D
    Steve.

  • #11 / Mar 23, 2009 4:14pm

    k00k

    21 posts

    Bingo! That did the trick Steve. Adding dynamic=“off” to the {exp:weblog:entries} tag inside the sidebar embed worked. I would think dynamic should default to off when specifying an explicit entry_id, no?

    I’m utilizing dynamic=“on” for my “regular” entries, so I didn’t turn those off.


    Thanks very much for going above and beyond.
    -steve

  • #12 / Mar 23, 2009 4:14pm

    Steve Abraham

    149 posts

    No problem - glad you got it working. 😊

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

ExpressionEngine News!

#eecms, #events, #releases