Skip to main content
Final version of working code
Source Link
stuartmcd69
  • 3.2k
  • 2
  • 15
  • 17

Well to start with you're capturing a single number, by adding stash around the EE channels tags, it will only ever capture/hold the last number or 0.

To hold all numbers you should use something like the following (NOTE: This is a theory and not verbatim code, refer the documents and experiment) I've done similar but not with Favorites so cannot confirm code of usage:

{exp:channel:entries channel="topic-content" search:topic-title="advertising" category="5" search:topic-view="IS_EMPTY" dynamic="no" parse="inward"}  
    {exp:stash:append name="fav_count" scope="user" trim="yes"}{exp:favorites:count entry_id="{entry_id}" favorites_member_id="CURRENT_USER"}+{/exp:stash:append}
  {/exp:channel:entries}
//NEW - Add bogus 0 to end of stash
{exp:stash:append name="fav_count" scope="user" trim="yes"}0{/exp:stash:append}

What this does is append the result of the favourites tags, trims any whitespace which would kill the sum action (next), adds a scope to the current user as well as adding the "+" symbol, which we can now utlise like this:

{exp:stash:parse}
  {exp:mx_calc parse="inward" expression="sum({exp:stash:get name='fav_count' scope='user'})"}
{/exp:stash:parse}

Assuming the stash capture results look like this: 0+1+2+0+ the sum would render like exp:mx_calc parse="inward" expression="sum(0+1+2+0+)

Failing that (or variations). Wrap each result in a unique class and use Javascript to find, record, add up and inject into a result tag.

UPDATE: Added a trailing '0' to the original capture (the trailing '+' was borking the math module. Inside the math function, used single quotes rather then doubles.

WORKING CODE!

{exp:channel:entries channel="topic-content" search:topic-title="advertising" category="5" search:topic-view="IS_EMPTY" dynamic="no" parse="inward" }
{exp:stash:append name="fav_count" parse_tags="yes" trim="yes" parse_conditionals="yes"} {exp:favorites:count entry_id="{entry_id}" favorites_member_id="CURRENT_USER"} {if "{count}" != "{total_results}"}+{/if} {/exp:stash:append} {/exp:channel:entries}WORKING CODE!

{exp:stash:parse process="end"} {exp:mx_calc expression="sum({stash:fav_count})"} {/exp:stash:parse}

{exp:channel:entries channel="topic-content" search:topic-title="advertising" category="5" search:topic-view="IS_EMPTY" dynamic="no" parse="inward" }  
  {exp:stash:append name="fav_count" parse_tags="yes" trim="yes" parse_conditionals="yes"}
    {exp:favorites:count entry_id="{entry_id}" favorites_member_id="CURRENT_USER"}
    {if "{count}" != "{total_results}"}+{/if}
  {/exp:stash:append}
{/exp:channel:entries}

{exp:stash:parse process="end"}
{exp:mx_calc expression="sum({stash:fav_count})"} 
{/exp:stash:parse} 

Well to start with you're capturing a single number, by adding stash around the EE channels tags, it will only ever capture/hold the last number or 0.

To hold all numbers you should use something like the following (NOTE: This is a theory and not verbatim code, refer the documents and experiment) I've done similar but not with Favorites so cannot confirm code of usage:

{exp:channel:entries channel="topic-content" search:topic-title="advertising" category="5" search:topic-view="IS_EMPTY" dynamic="no" parse="inward"}  
    {exp:stash:append name="fav_count" scope="user" trim="yes"}{exp:favorites:count entry_id="{entry_id}" favorites_member_id="CURRENT_USER"}+{/exp:stash:append}
  {/exp:channel:entries}
//NEW - Add bogus 0 to end of stash
{exp:stash:append name="fav_count" scope="user" trim="yes"}0{/exp:stash:append}

What this does is append the result of the favourites tags, trims any whitespace which would kill the sum action (next), adds a scope to the current user as well as adding the "+" symbol, which we can now utlise like this:

{exp:stash:parse}
  {exp:mx_calc parse="inward" expression="sum({exp:stash:get name='fav_count' scope='user'})"}
{/exp:stash:parse}

Assuming the stash capture results look like this: 0+1+2+0+ the sum would render like exp:mx_calc parse="inward" expression="sum(0+1+2+0+)

Failing that (or variations). Wrap each result in a unique class and use Javascript to find, record, add up and inject into a result tag.

UPDATE: Added a trailing '0' to the original capture (the trailing '+' was borking the math module. Inside the math function, used single quotes rather then doubles.

WORKING CODE!

{exp:channel:entries channel="topic-content" search:topic-title="advertising" category="5" search:topic-view="IS_EMPTY" dynamic="no" parse="inward" }
{exp:stash:append name="fav_count" parse_tags="yes" trim="yes" parse_conditionals="yes"} {exp:favorites:count entry_id="{entry_id}" favorites_member_id="CURRENT_USER"} {if "{count}" != "{total_results}"}+{/if} {/exp:stash:append} {/exp:channel:entries}

{exp:stash:parse process="end"} {exp:mx_calc expression="sum({stash:fav_count})"} {/exp:stash:parse}

Well to start with you're capturing a single number, by adding stash around the EE channels tags, it will only ever capture/hold the last number or 0.

To hold all numbers you should use something like the following (NOTE: This is a theory and not verbatim code, refer the documents and experiment) I've done similar but not with Favorites so cannot confirm code of usage:

{exp:channel:entries channel="topic-content" search:topic-title="advertising" category="5" search:topic-view="IS_EMPTY" dynamic="no" parse="inward"}  
    {exp:stash:append name="fav_count" scope="user" trim="yes"}{exp:favorites:count entry_id="{entry_id}" favorites_member_id="CURRENT_USER"}+{/exp:stash:append}
  {/exp:channel:entries}
//NEW - Add bogus 0 to end of stash
{exp:stash:append name="fav_count" scope="user" trim="yes"}0{/exp:stash:append}

What this does is append the result of the favourites tags, trims any whitespace which would kill the sum action (next), adds a scope to the current user as well as adding the "+" symbol, which we can now utlise like this:

{exp:stash:parse}
  {exp:mx_calc parse="inward" expression="sum({exp:stash:get name='fav_count' scope='user'})"}
{/exp:stash:parse}

Assuming the stash capture results look like this: 0+1+2+0+ the sum would render like exp:mx_calc parse="inward" expression="sum(0+1+2+0+)

Failing that (or variations). Wrap each result in a unique class and use Javascript to find, record, add up and inject into a result tag.

UPDATE: Added a trailing '0' to the original capture (the trailing '+' was borking the math module. Inside the math function, used single quotes rather then doubles.

WORKING CODE!

{exp:channel:entries channel="topic-content" search:topic-title="advertising" category="5" search:topic-view="IS_EMPTY" dynamic="no" parse="inward" }  
  {exp:stash:append name="fav_count" parse_tags="yes" trim="yes" parse_conditionals="yes"}
    {exp:favorites:count entry_id="{entry_id}" favorites_member_id="CURRENT_USER"}
    {if "{count}" != "{total_results}"}+{/if}
  {/exp:stash:append}
{/exp:channel:entries}

{exp:stash:parse process="end"}
{exp:mx_calc expression="sum({stash:fav_count})"} 
{/exp:stash:parse} 

Well to start with you're capturing a single number, by adding stash around the EE channels tags, it will only ever capture/hold the last number or 0.

To hold all numbers you should use something like the following (NOTE: This is a theory and not verbatim code, refer the documents and experiment) I've done similar but not with Favorites so cannot confirm code of usage:

{exp:channel:entries channel="topic-content" search:topic-title="advertising" category="5" search:topic-view="IS_EMPTY" dynamic="no" parse="inward"}  
    {exp:stash:append name="fav_count" scope="user" trim="yes"}{exp:favorites:count entry_id="{entry_id}" favorites_member_id="CURRENT_USER"}+{/exp:stash:append}
  {/exp:channel:entries}
//NEW - Add bogus 0 to end of stash
{exp:stash:append name="fav_count" scope="user" trim="yes"}0{/exp:stash:append}

What this does is append the result of the favourites tags, trims any whitespace which would kill the sum action (next), adds a scope to the current user as well as adding the "+" symbol, which we can now utlise like this:

{exp:stash:parse}
  {exp:mx_calc parse="inward" expression="sum({exp:stash:get name='fav_count' scope='user'})"}
{/exp:stash:parse}

Assuming the stash capture results look like this: 0+1+2+0+ the sum would render like exp:mx_calc parse="inward" expression="sum(0+1+2+0+)

Failing that (or variations). Wrap each result in a unique class and use Javascript to find, record, add up and inject into a result tag.

UPDATE: Added a trailing '0' to the original capture (the trailing '+' was borking the math module. Inside the math function, used single quotes rather then doubles.

WORKING CODE!

{exp:channel:entries channel="topic-content" search:topic-title="advertising" category="5" search:topic-view="IS_EMPTY" dynamic="no" parse="inward" }
{exp:stash:append name="fav_count" parse_tags="yes" trim="yes" parse_conditionals="yes"} {exp:favorites:count entry_id="{entry_id}" favorites_member_id="CURRENT_USER"} {if "{count}" != "{total_results}"}+{/if} {/exp:stash:append} {/exp:channel:entries}

{exp:stash:parse process="end"} {exp:mx_calc expression="sum({stash:fav_count})"} {/exp:stash:parse}

Well to start with you're capturing a single number, by adding stash around the EE channels tags, it will only ever capture/hold the last number or 0.

To hold all numbers you should use something like the following (NOTE: This is a theory and not verbatim code, refer the documents and experiment) I've done similar but not with Favorites so cannot confirm code of usage:

{exp:channel:entries channel="topic-content" search:topic-title="advertising" category="5" search:topic-view="IS_EMPTY" dynamic="no" parse="inward"}  
    {exp:stash:append name="fav_count" scope="user" trim="yes"}{exp:favorites:count entry_id="{entry_id}" favorites_member_id="CURRENT_USER"}+{/exp:stash:append}
  {/exp:channel:entries}
//NEW - Add bogus 0 to end of stash
{exp:stash:append name="fav_count" scope="user" trim="yes"}0{/exp:stash:append}

What this does is append the result of the favourites tags, trims any whitespace which would kill the sum action (next), adds a scope to the current user as well as adding the "+" symbol, which we can now utlise like this:

{exp:stash:parse}
  {exp:mx_calc parse="inward" expression="sum({exp:stash:get name='fav_count' scope='user'})"}
{/exp:stash:parse}

Assuming the stash capture results look like this: 0+1+2+0+ the sum would render like exp:mx_calc parse="inward" expression="sum(0+1+2+0+)

Failing that (or variations). Wrap each result in a unique class and use Javascript to find, record, add up and inject into a result tag.

UPDATE: Added a trailing '0' to the original capture (the trailing '+' was borking the math module. Inside the math function, used single quotes rather then doubles.

Well to start with you're capturing a single number, by adding stash around the EE channels tags, it will only ever capture/hold the last number or 0.

To hold all numbers you should use something like the following (NOTE: This is a theory and not verbatim code, refer the documents and experiment) I've done similar but not with Favorites so cannot confirm code of usage:

{exp:channel:entries channel="topic-content" search:topic-title="advertising" category="5" search:topic-view="IS_EMPTY" dynamic="no" parse="inward"}  
    {exp:stash:append name="fav_count" scope="user" trim="yes"}{exp:favorites:count entry_id="{entry_id}" favorites_member_id="CURRENT_USER"}+{/exp:stash:append}
  {/exp:channel:entries}
//NEW - Add bogus 0 to end of stash
{exp:stash:append name="fav_count" scope="user" trim="yes"}0{/exp:stash:append}

What this does is append the result of the favourites tags, trims any whitespace which would kill the sum action (next), adds a scope to the current user as well as adding the "+" symbol, which we can now utlise like this:

{exp:stash:parse}
  {exp:mx_calc parse="inward" expression="sum({exp:stash:get name='fav_count' scope='user'})"}
{/exp:stash:parse}

Assuming the stash capture results look like this: 0+1+2+0+ the sum would render like exp:mx_calc parse="inward" expression="sum(0+1+2+0+)

Failing that (or variations). Wrap each result in a unique class and use Javascript to find, record, add up and inject into a result tag.

UPDATE: Added a trailing '0' to the original capture (the trailing '+' was borking the math module. Inside the math function, used single quotes rather then doubles.

WORKING CODE!

{exp:channel:entries channel="topic-content" search:topic-title="advertising" category="5" search:topic-view="IS_EMPTY" dynamic="no" parse="inward" }
{exp:stash:append name="fav_count" parse_tags="yes" trim="yes" parse_conditionals="yes"} {exp:favorites:count entry_id="{entry_id}" favorites_member_id="CURRENT_USER"} {if "{count}" != "{total_results}"}+{/if} {/exp:stash:append} {/exp:channel:entries}

{exp:stash:parse process="end"} {exp:mx_calc expression="sum({stash:fav_count})"} {/exp:stash:parse}

added 303 characters in body
Source Link
stuartmcd69
  • 3.2k
  • 2
  • 15
  • 17

Well to start with you're capturing a single number, by adding stash around the EE channels tags, it will only ever capture/hold the last number or 0.

To hold all numbers you should use something like the following (NOTE: This is a theory and not verbatim code, refer the documents and experiment) I've done similar but not with Favorites so cannot confirm code of usage:

{exp:channel:entries channel="topic-content" search:topic-title="advertising" category="5" search:topic-view="IS_EMPTY" dynamic="no" parse="inward"}  
    {exp:stash:append name="fav_count" scope="user" trim="yes"}{exp:favorites:count entry_id="{entry_id}" favorites_member_id="CURRENT_USER"}+{/exp:stash:append}
  {/exp:channel:entries}
//NEW - Add bogus 0 to end of stash
{exp:stash:append name="fav_count" scope="user" trim="yes"}0{/exp:stash:append}

What this does is append the result of the favourites tags, trims any whitespace which would kill the sum action (next), adds a scope to the current user as well as adding the "+" symbol, which we can now utlise like this:

{exp:stash:parse}
  {exp:mx_calc parse="inward" expression="sum({exp:stash:get name="fav_count"name='fav_count' scope="user"scope='user'})"}
{/exp:stash:parse}

Assuming the stash capture results look like this: 0+1+2+0+ the sum would render like exp:mx_calc parse="inward" expression="sum(0+1+2+0+)

Failing that (or variations). Wrap each result in a unique class and use Javascript to find, record, add up and inject into a result tag.

UPDATE: Added a trailing '0' to the original capture (the trailing '+' was borking the math module. Inside the math function, used single quotes rather then doubles.

Well to start with you're capturing a single number, by adding stash around the EE channels tags, it will only ever capture/hold the last number or 0.

To hold all numbers you should use something like the following (NOTE: This is a theory and not verbatim code, refer the documents and experiment) I've done similar but not with Favorites so cannot confirm code of usage:

{exp:channel:entries channel="topic-content" search:topic-title="advertising" category="5" search:topic-view="IS_EMPTY" dynamic="no" parse="inward"}  
    {exp:stash:append name="fav_count" scope="user" trim="yes"}{exp:favorites:count entry_id="{entry_id}" favorites_member_id="CURRENT_USER"}+{/exp:stash:append}
  {/exp:channel:entries}

What this does is append the result of the favourites tags, trims any whitespace which would kill the sum action (next), adds a scope to the current user as well as adding the "+" symbol, which we can now utlise like this:

{exp:stash:parse}
  {exp:mx_calc parse="inward" expression="sum({exp:stash:get name="fav_count" scope="user"})"}
{/exp:stash:parse}

Assuming the stash capture results look like this: 0+1+2+0+ the sum would render like exp:mx_calc parse="inward" expression="sum(0+1+2+0+)

Failing that (or variations). Wrap each result in a unique class and use Javascript to find, record, add up and inject into a result tag.

Well to start with you're capturing a single number, by adding stash around the EE channels tags, it will only ever capture/hold the last number or 0.

To hold all numbers you should use something like the following (NOTE: This is a theory and not verbatim code, refer the documents and experiment) I've done similar but not with Favorites so cannot confirm code of usage:

{exp:channel:entries channel="topic-content" search:topic-title="advertising" category="5" search:topic-view="IS_EMPTY" dynamic="no" parse="inward"}  
    {exp:stash:append name="fav_count" scope="user" trim="yes"}{exp:favorites:count entry_id="{entry_id}" favorites_member_id="CURRENT_USER"}+{/exp:stash:append}
  {/exp:channel:entries}
//NEW - Add bogus 0 to end of stash
{exp:stash:append name="fav_count" scope="user" trim="yes"}0{/exp:stash:append}

What this does is append the result of the favourites tags, trims any whitespace which would kill the sum action (next), adds a scope to the current user as well as adding the "+" symbol, which we can now utlise like this:

{exp:stash:parse}
  {exp:mx_calc parse="inward" expression="sum({exp:stash:get name='fav_count' scope='user'})"}
{/exp:stash:parse}

Assuming the stash capture results look like this: 0+1+2+0+ the sum would render like exp:mx_calc parse="inward" expression="sum(0+1+2+0+)

Failing that (or variations). Wrap each result in a unique class and use Javascript to find, record, add up and inject into a result tag.

UPDATE: Added a trailing '0' to the original capture (the trailing '+' was borking the math module. Inside the math function, used single quotes rather then doubles.

Source Link
stuartmcd69
  • 3.2k
  • 2
  • 15
  • 17
Loading