If statement from an array

PatriaCo
PatriaCo
@the-patria-company
8 years ago
349 posts
I am trying to construct an if statement that checks all the array data in $_items for $_items.comment_parent_id "that == its own" $_items._item_id

This would indicate that the item has been replied to with threading enabled.

{if $item._item_id == $_item.comment_parent_id (check all records within the array to see if one exists and if yes return true)}

Thanks for the help.


--
The Patria Company - patriaco.com / quality-trades.com / a-t.life - doing Jamroom since v3

updated by @the-patria-company: 10/30/16 10:34:11PM
michael
@michael
8 years ago
7,715 posts
{$a_flag = false}
{if(isset($_items) && is_array($_items)}
  {foreach $_items as $item}
     {if $item.comment_parent_id == "something"}
        {$a_flag = true}
     {/if}
  {/foreach}
{/if}

{if $a_flag}
  // that flag was found in the array so do something......
{/if}
PatriaCo
PatriaCo
@the-patria-company
8 years ago
349 posts
Thank you so much, I am very close. I need to set the "outer" parameter for the comment being displayed. It makes up this part of your code:

{if $item.comment_parent_id == "something"}

Something needs to be the $item._item_id for the comment being displayed.

{jrCore_module_url module="jrComment" assign="murl"}
// select each comment in the array
{foreach $_items as $item}
// set the item_id as the parent_id to be used later -- !! This is the part I have wrong !! --
{$_item._item_id = $parent_id}
// code that displays the top portion of the comment
{$a_flag = false}
{if (isset($_items) && is_array($_items))}
  {foreach $_items as $item}
       {if $item.comment_parent_id == $parent_id}  // here is where I need to have the outer param
            {$a_flag = true}
       {/if}
   {/foreach}
{/if}

{if $a_flag}
    Show Replies
{/if}

Currently this code is returning true all the time and a debug does not generate any results for $parent_id... so I know I have something wrong.

Thanks again :)


--
The Patria Company - patriaco.com / quality-trades.com / a-t.life - doing Jamroom since v3
michael
@michael
8 years ago
7,715 posts
I would recommend against changing the $_item.

This part is wrong:
{$_item._item_id = $parent_id}
You're looping over all the arrays inside $_item, so if you want to set the array of the particular one that your working on to a different value, you have to identify it.

Each item in $_items has a key, so you need to use that to target the current subject of the loop.
{foreach $_items as $key => $item}   
   {$_items[$key]['_item_id'] = $parent_id}

This is not normally code that goes into templates, it feels more like it should be a module altering the $_items array before it gets to here.

Docs: "Events and Listeners"
https://www.jamroom.net/the-jamroom-network/documentation/jamroom-developers-guide/1011/events-and-listeners

Tags