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.

Conditional to load scripts based on embed OR segment

June 16, 2010 8:59am

Subscribe [2]
  • #1 / Jun 16, 2010 8:59am

    birdie

    68 posts

    Hi, having a bit of trouble figuring this one out, any tips appreciated…

    I have my category list hidden by jQuery, and only visible on “article” pages and category listings. Articles are working fine, by using conditionals to load a different script based on embed:blogcats content, like so:

    {if '{embed:blogcats}' == 'catsclosed'}
    ...path to script to hide category sidebar
    {if:else}
    ...path to script to show category sidebar
    {/if}

    But I need to add a way to detect if the user is viewing a category listing page, and also show the categories list open on there. Something like this:

    {if '{embed:blogcats}' == 'catsclosed'}
    ...path to script to hide category sidebar
    {if:elseif '{segment_2}' == 'category'}
    ...path to script to show category sidebar
    {if:else}
    ...path to script to show category sidebar
    {/if}

    I’ve been trying all sorts of ways to do it but I can’t seem to get the right combination.

    Thanks!

    Cormac


    Edit: Oh right, script source links are [removed]. Updated.

  • #2 / Jun 16, 2010 11:12am

    Wouter Vervloet

    758 posts

    Hi Cormac,

    Have you had a look at the MD Detect Page Type plugin? It takes care of the hassle of detecting which type of page it is.

    What code are you using to display the category listing? It depends on how you’re displaying them what kind of method to use to ‘open’ a certain category.

    Greetz,
    Wouter

  • #3 / Jun 16, 2010 1:39pm

    birdie

    68 posts

    Thanks Wouter, I’ll give that plugin a try and see how it works out.

    I’m using the following code for the categories list, it’s within an embed “blogsidebar.php”

    <ul class="blogNav">
    {exp:weblog:categories weblog="blog" style="linear" id="subnav" show_empty="no"}
    <li>
    {if segment_2 == 'C{category_id}'}
    <a href="http://{path=%27blog/%27}" class="current">{category_name}</a></li>
    {if:else}
    <a href="http://{path=blog/}">{category_name}</a></li>
    {/if}
    {/exp:weblog:categories}
    
    </ul>
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases