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.

Comments Module author_id variable, overwritten in channel loop

July 20, 2011 10:36am

Subscribe [2]
  • #1 / Jul 20, 2011 10:36am

    I have a situation where I am showing the newest entry from a given channel, on a page where the url contains neither entry_id or entry_url_title. We have to add comments to this showing, and since it is not able to fetch the related entry dynamically, I specify the entry_id by putting the comments loop inside of the channel loop. I don’t see how I can get the entry_id in other ways.

    The problem that arises when I put the comments loop inside of the channel loop, is that all the comment variables are overwritten by the ones from the entry, thus I cannot display the commenter nor link to his profile.

    Help would be appreciated. Thanks

    /Rasmus

  • #2 / Jul 20, 2011 10:53pm

    Dan Decker

    7338 posts

    Hi Rasmus,

    Can you post an example of your template code?

    Even if exp:channel:entries is pulling just the latest entry in from a given channel, that entry “knows” a lot about itself, including it’s own entry_id. There are several ways you can “pass along” information to a template that will display the comments for the entry.

    Here is a very basic single entry template:

    {exp:channel:entries channel="my_channel" limit="1"}
    
    {title}
    
    {body}
    
    <a href="http://{path=channel/comments}">Join the discussion!</a>
    
    {/exp:channel:entries}

    Here is the template that one is linking to via the {path} global variable, documented here.

    {exp:channel:entries channel="my_channel" limit="1"}
    
    {title}
    
    {body}
    
    {/exp:channel:entries}
    {exp:comment:entries channel="my_channel" sort="asc" limit="20"}
    
    
    
    {comment}
    
    
    
    By {name} on {comment_date format="%Y %m %d"}
    
    
    
    {/exp:comment:entries}

    ExpressionEngine operates on several dynamic factors that allow for this to work.

    Also, please note that the documentation recommends against nesting the {exp:comment:entries} tag inside {exp:channel:entries}

    Please let us know if you need further assistance with this issue and I hope I was able to help you along 😊

    Best,

  • #3 / Jul 20, 2011 11:05pm

    As I already mentioned in my question, I do not have either the url_title nor the entry_id in the url, and thus the {path} global variable is useless to me. I am not interested in an anchor to the comments, I want them on the same page. I have read the documentation. If I hadn’t I wouldn’t be posting in here.

    /Rasmus

  • #4 / Jul 21, 2011 12:27am

    Dan Decker

    7338 posts

    Hi Rasmus,

    I apologize for the misunderstanding as far as linking to a different template is concerned.

    You are wanting a template that pulls the most recent post from a channel, correct? You want that template to include comments that are associated with that entry, correct? This scenario, for the most part, describes a single entry template. The second block of template code above will do what you are looking for.

    In the instance where you want to pull the most recent entry, you just supply {exp:channel:entries} with the limit=“1” parameter. That will cause it to pull the most recent entry from the channel. You needn’t be concerned with supply the {exp:comment:entries} tag with any additional information. By being included in the single entry template, ExpressionEngine will supplying the comment block with the information it needs dynamically.

    Plug this code into a template:

    {exp:channel:entries channel="my_channel" limit="1"}
    
    {title}
    
    {body}
    
    {/exp:channel:entries}
    {exp:comment:entries channel="my_channel" sort="asc" limit="20"}
    
    
    
    {comment}
    
    
    
    By {name} on {comment_date format="%Y %m %d"}
    
    
    
    {/exp:comment:entries}

    And see if you don’t automatically get the results you desire. Be sure to change the channel=“” parameter to match your actual channel name.

    Let me know if this working example code gets you what you are looking for.

    Best,

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

ExpressionEngine News!

#eecms, #events, #releases