0

I have a .sidebar template which is in a template shared by a few inner pages of the site. It pulls in the channel based on a preload tag on the page it is embedded in.

I have a conditional set to display certain content based on what page it's on, however no content is being displayed.

Here is the full sidebar code I have right now:

<aside>
<h2 class="sidebar-title"><a class="up" href="#">About</a></h2>
<div class="expand">
    {exp:channel:entries channel="{embed:chan}" limit="1" category="{embed:cat}"}
    {if sidebar_title != "" AND sidebar_description != ""}
    <section class="sidebar-description">
        <h2>{sidebar_title}</h2>
        <p>{sidebar_description}</p>
    </section>
    <hr />
    {/if}
    {embed="_includes/.sidebar-posts"}
    <hr />
    <section>
        {if segment_1 == "blog"}
        <h2>Follow me</h2>
        <p>{follow_me_blurb}</p>
        <ul>
            <li><p><a href="#">Facebook</a></p></li>
                            <li><p><a href="#">Instagram</a></p></li>
                            <li><p><a href="#">Twitter</a></p></li>
                            <li><p><a href="#">Pinterest</a></p></li>
        </ul>               
        {/if}
        {if segment_1 != "blog"}
            {if bring_content != ""}
            <h2>Bring</h2>
            <p>{bring_content}</p>
            {/if}
            {if tip_content != ""}
            <h2>Tips</h2>
            <p>{tip_content}</p>
            {/if}
        {/if}
    </section>
    <section class="sidebar-links">
        <a href="#" class="small"><strong>Blog</strong></a>
        <a href="#" class="large">Shop &raquo;</a>
        <a href="#" class="large">&laquo; Discover</a>
        <a href="#" class="small"><strong>Follow</strong></a>
    </section>
    {/exp:channel:entries}
</div>

On my main page, I embed the sidebar, and set preload at the top of my template:

{preload_replace:chan="inner_page_details"}
{preload_replace:cat="7"}

_edit: I discovered this issue happened because it wasn't reading the channel preload_replace included in the main templates. I had to hard-code the channel in, but am unable to discover a solution for the categories_

5
  • I also verified it isn't a typo, so I have no further ideas. – Alexa L Apr 12 '13 at 22:05
  • You're not showing your channel entries tags; it's likely the problem is there. – Tyssen Apr 12 '13 at 23:19
  • Tyssen's right, can you post your code so we can see where your {exp:channel:entries} tags are? – erwinheiser Apr 13 '13 at 12:22
  • I updated it to include the full sidebar code. I know it is an issue with the nested conditional, because I tried simply putting <p>Not blog.</p> and it showed up perfectly fine on the non-blog pages. – Alexa L Apr 15 '13 at 18:56
  • I tweaked the conditional statement which works now, but it seems that my channel="{embed:chan}" isnt working...I had to hard-code the channel name in, but I can't do the same thing for the category. Apparently my preload_replace in my main template isn't replacing the {cat} variable when the sidebar template is rendered. – Alexa L Apr 15 '13 at 23:26
1

I'm assuming that when you say sections other than /blog are not displaying content that you also mean that sections which are /blog are displaying content(?).

If this is the case then it may very well be the {if:else} causing the problem so try this:

{if segment_1 == "blog"}
    ...
{/if}

{if segment_1 != "blog"}
    NOT blog section
    other nested conditionals here
{/if}

Let me know if that helps in getting something to display for sections other than /blog/.

4
  • Also, make sure to output {segment_1} on it's own so that you can see exactly what is being output. – Ian Apr 13 '13 at 17:22
  • It is not an issue with that particular conditional being incorrect, it is an issue with the nested conditional inside the !="blog" statement. – Alexa L Apr 15 '13 at 18:58
  • That would suggest that the values of {bring_content} and {tip_content} aren't matching empty strings if it's those two which are tripping things up. Try outputting those variables on their own surrounded by something like an asterisk to see if there are extra whitespaces creeping in which could be causing the it to not be empty (whitespace is something even if it looks like nothing). – Ian Apr 15 '13 at 19:06
  • There was an odd character being rendered that wasn't showing in the content editor...I fixed that but it didn't work. It turns out that my {embed:chan} wasn't pulling in the channel...so it was reading the fields as being empty. I did implement this method of if statements as well to be safer. – Alexa L Apr 15 '13 at 23:28
0

Looking at the documentation:

http://ellislab.com/expressionengine/user-guide/templates/globals/conditionals.html

The first user comment mentions enclosing your variables in quotes, so maybe you should try:

{if "{bring_content}" != ""}
   <h2>Bring</h2>
   <p>{bring_content}</p>
{/if}
{if "{tip_content}" != ""}
   <h2>Tips</h2>
   <p>{tip_content}</p>
{/if}

Conditionals can be fickle sometimes. The third comment in the documentation mentions that by adding the quotes around your tags, it parses it as an advanced conditional vs a simple conditional.

3
  • Quotes shouldn't be needed for segment variables but it never hurts to try to be sure. – Ian Apr 13 '13 at 17:21
  • Not for the segment variables. Those should be fine. – Johnathan Waters Apr 13 '13 at 17:30
  • This didn't work. I had tried doing that before, which still displayed nothing. – Alexa L Apr 15 '13 at 18:56
0

Apparently it wasn't completely an issue with the nested conditional. After tweaking that I was able to display plain html inside it. The issue was that the {preload_replace} for my channel in the main templates wasn't being used to replace the channel in my sidebar template. I had to hardcode the channel name into the sidebar. I will have to find some solution to get the category {preload_replace} to work as well.

I am marking this topic answered, since the title no longer applies to this issue. Thanks for the help guys!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.