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.

Categories backspace in embedded template

November 08, 2011 3:53am

Subscribe [3]
  • #1 / Nov 08, 2011 3:53am

    jaredL

    4 posts

    I’m displaying parent categories in one template and embedding the child categories for each parent in a separate template. I’m doing this so the child categories can have a different style than the parents.

    Parent Categories:

    {exp:channel:categories channel="dialogue" category_group="54" parent_only="yes" show="not 336"}
     <a href="/dialogue/category/{category_url_title}"><div class="editorbox {if category_url_title == '{segment_3}'}editorbox_selected{/if}">_  <div class="editorinfo">_   <h4>{category_name}</h4><p>_   {embed="dialogue/sub_cats" parent="{category_id}"}_  </div>_  <div class="clear"></div>_ </div></a><br />
    {/exp:channel:categories}

    Child Categories:

    {exp:channel:categories channel="dialogue" category_group="54" style="linear" " backspace="10"}
     {if parent_id=="{embed:parent}"}
       {category_name}, 
     {/if}
    {/exp:channel:categories}

    It’s all working fine, except the backspace parameter is only working for the set of child categories under the last parent. See attached image. I’m trying to get rid of the trailing comma, but it’s only working on the bottom item.

     

  • #2 / Nov 08, 2011 6:20am

    silenz

    1651 posts

    The explanation of this phenomenon is somewhat complicated. To cut it short the conditional creates various amounts of whitespace and linebreaks with which the backspace-parameter cannot cope.

    Your best bet would probably be to use some third-party category-plugin to fetch the child categories more elegantly. GWcode Categories for example.

    Then replacing the content of “dialogue/sub_cats” with

    {exp:gwcode_categories channel="dialogue" style="linear" incl_self="no" cat_id="{embed:parent}" backspace="1"}
    {cat_name}, 
    {/exp:gwcode_categories}

    should do the trick.

  • #3 / Nov 08, 2011 12:08pm

    jaredL

    4 posts

    Awesome, worked perfectly. Thanks!

  • #4 / Nov 08, 2011 8:35pm

    Sean C. Smith

    3818 posts

    JaredL,

    Happy to see that your problem has been resolved. Will close this thread. Feel free to post again as needed.

    Silenz, thanks for the assist.

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

ExpressionEngine News!

#eecms, #events, #releases