3

I'm having trouble grasping the usefulness of {if allow_comments}. The comment:entries loop and comments form code are both supposed to be outside of channel:entries, but presumable {if allow_comments} only works inside channel:entries. So I find myself having to use the channel:entries tag repeatedly around the elements in order to use the conditional. So my code get's all ugly like this:

{exp:channel:entries channel="blog" disable="category_fields|member_data|pagination" dynamic="no" status="Open|Featured" url_title="{segment_3}" limit="1" require_entry="yes"}    
{if allow_comments && comment_total > 0}
                <div class="dividerBig">.</div>
                <h1>Comments</h1>
                <ul class="comments">
                {/if}<!-- end allow comments -->
            {/exp:channel:entries}

                    {exp:comment:entries channel="blog" url_title="{segment_3}" orderby="date" sort="asc"}
                    <li>
                        <h3><span>{name}</span></h3>
                        {comment}
                        <span class="date">{comment_date format="%F %d, %Y"}</span>
                    </li>
                    {/exp:comment:entries}

            {exp:channel:entries channel="blog" disable="category_fields|member_data|pagination" dynamic="no" status="Open|Featured" url_title="{segment_3}" limit="1" require_entry="yes"}
                {if allow_comments && comment_total > 0}    
                </ul>
                {/if}<!-- end allow comments -->

                {if allow_comments}
                <div class="dividerBig">.</div>
                <h1>Write a comment</h1>
                {/if}<!-- end allow comments -->
            {/exp:channel:entries}

                {exp:comment:form channel="blog" url_title="{segment_3}" preview="blog/comment" form_class="default" return="{homepage}blog/comment-thanks"}

Etc...

This looks rediculous and I'm sure using so many channel:entries tags is a performance hit, but how else do you effectively use the {if allow_comments} conditional?

Do people put their comment:entries and comments forms inside embed templates? Is that any better?

2

I usually do something like this, within my Channel Entries tag:

{if comment_total > "0" || allow_comments}
    {embed="blog/_comment_list"}
{/if}

{if allow_comments}
    {embed="blog/_comment_add"}
{if:else}
    <p>Sorry, comments are closed.</p>
{/if} 

With the appropriate chunks of comment:entries and comment:form code in those embeds respectively. Much cleaner.

2
  • Agree that's much cleaner. Do you know what the performance difference is of using embeds vs. having the comments and form in the same template? – Benek Lisefski Feb 11 '13 at 22:44
  • I don't have measurements to that effect, but on a single entry template it will be minor. – Derek Hogue Feb 11 '13 at 23:24

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.