solved User Defined Limit - Assign Variable From Form?

Ken Rich
Ken Rich
@ken-rich
8 years ago
926 posts
On my Combined Sales Module this works.

{jrCore_list module="jrVideo" profile_id=$item._profile_id search1="video_file_item_price > 0" order_by="video_display_order numerical_asc" limit="2"}

However, I want the profile owner to have control over the number of items displayed. So I added a text box with the form designer. The number inputted by the profile owner is available under $item as sales_videos_limit in the item_detail.tpl (shows in debug).

However, the limit function can't seem to utilize it and gives an error if I write:

{jrCore_list module="jrVideo" profile_id=$item._profile_id order_by="video_display_order numerical_asc" limit="sales_videos_limit"}

I thought it might be a syntax issue so I tried various combinations like.

limit="$item.sales_videos_limit"
limit="$item._sales_videos_limit"
limit="$_item._sales_videos_limit"
limit="_sales_videos_limit"

Nothing works so how can I assign a user-defined variable as the limit?


--

Ken Rich
indiegospel.net

updated by @ken-rich: 07/30/16 11:43:52PM
douglas
@douglas
8 years ago
2,791 posts
This might work as long as $item._profile_id is available in the template where your jrCore_list call is located.

Assign the limit variable:
{capture name="limit_template" assign="limit_template_row"}
    {literal}
        {if isset($_items)}
            {foreach $_items as $item}
                {$item.sales_videos_limit}
            {/foreach}
        {/if}
    {/literal}
{/capture}
{jrCore_list module="jrVideo" profile_id=$item._profile_id limit="1" template=$limit_template_row assign="svl"}

jrCore_list function:
{if isset($svl) && $svl > 0}
    {jrCore_list module="jrVideo" profile_id=$item._profile_id search1="video_file_item_price > 0" order_by="video_display_order numerical_asc" limit=$svl}
{else}
    {jrCore_list module="jrVideo" profile_id=$item._profile_id search1="video_file_item_price > 0" order_by="video_display_order numerical_asc" limit="2"}
{/if}

Hope this helps!


--

Douglas Hackney
Jamroom Team - Designer/Developer/Support
FAQ-Docs-Help Videos
Ken Rich
Ken Rich
@ken-rich
8 years ago
926 posts
douglas:
This might work as long as $item._profile_id is available in the template where your jrCore_list call is located.

If I am understanding correctly, that would be my item_list.tpl and $item._profile_id is already in use there, so it probally will work.

However, there is already a foreach statement running there. So I'm a little confused about where to add this one, outside or inside of the other.

So currently it looks like this with the other content categories removed for simplicity.

 {jrCore_module_url module="xxSales" assign="murl"}
{if isset($_items)}
    {foreach from=$_items item="item"}
       <div class="item">

            <div class="block_config">
                {jrCore_item_list_buttons module="xxSales" item=$item}
            </div>         
        
           {if strlen($item.sales_editor) > 0}
            {$item.sales_editor|jrCore_format_string:$item.profile_quota_id}
            {/if}           
           
{* Other Categories Removed But Function Like Video *}
  {* Video *}

{if $item.sales_videos == 'on'}

<div class="title">        
         <h1>Video</h1> <input type="button" value="View All" class="form_button" style="float: right;" onclick="jrCore_window_location('{$jamroom_url}/{$_post.module_url}/uploaded_video');"> 
         
        <div class="block_content">
        {jrCore_list module="jrVideo" profile_id=$item._profile_id search1="video_file_item_price > 0" order_by="video_display_order numerical_asc" limit="2"}
        </div>          
</div> 
{/if} 

            <br>
        </div>

    {/foreach}
{/if}


So should the capture/assign with IT'S OWN foreach statement run within the EXISTING foreach statement like this:

 {jrCore_module_url module="xxSales" assign="murl"}
{if isset($_items)}
    {foreach from=$_items item="item"}
       <div class="item">

            <div class="block_config">
                {jrCore_item_list_buttons module="xxSales" item=$item}
            </div>         
        
           {if strlen($item.sales_editor) > 0}
            {$item.sales_editor|jrCore_format_string:$item.profile_quota_id}
            {/if}           
           
           
{capture name="limit_template" assign="limit_template_row"}
    {literal}
        {if isset($_items)}
            {foreach $_items as $item}
                {$item.sales_videos_limit}
            {/foreach}
        {/if}
    {/literal}
{/capture}
{jrCore_list module="jrVideo" profile_id=$item._profile_id limit="1" template=$limit_template_row assign="svl"}

{* Other Categories Removed But Function Like Video *}

    {* Video *}

{if $item.sales_videos == 'on'}

<div class="title">        
         <h1>Video</h1> <input type="button" value="View All" class="form_button" style="float: right;" onclick="jrCore_window_location('{$jamroom_url}/{$_post.module_url}/uploaded_video');"> 
         
        <div class="block_content">
        {if isset($svl) && $svl > 0}
    {jrCore_list module="jrVideo" profile_id=$item._profile_id search1="video_file_item_price > 0" order_by="video_display_order numerical_asc" limit=$svl}
{else}
    {jrCore_list module="jrVideo" profile_id=$item._profile_id search1="video_file_item_price > 0" order_by="video_display_order numerical_asc" limit="2"}
        </div>          
</div> 
{/if}       
            <br>
        </div>

    {/foreach}
{/if}


Then would I just repeat the process for all my other categories (substituting names) such that I end up with half a dozen foreach statements inside a foreach statement - or would the server melt????

Or is the proper way to have only the existing foreach statement and add all the capture/assigns to it. If so, what would that look like? Perhaps something like this for the video example?

{capture name="limit_template" assign="limit_template_row"}{$item.sales_videos_limit}{/capture}
{jrCore_list module="jrVideo" profile_id=$item._profile_id limit="1" template=$limit_template_row assign="svl"}



--

Ken Rich
indiegospel.net

updated by @ken-rich: 04/27/16 01:50:22PM
Ken Rich
Ken Rich
@ken-rich
8 years ago
926 posts
I experimented and got it working without using multiple foreach statements. I was able to eliminate my checkbox for show/no show as well because zero accomplishes the same.

So final code looks like:


{* Video *}

{capture name="limit_template" assign="limit_template_row"}    {$item.sales_videos_limit}    {/capture}
{jrCore_list module="jrVideo" profile_id=$item._profile_id limit="1" template=$limit_template_row assign="svl"}    

{if isset($svl) && $svl > 0}

<div class="title">        
         <h1>Video</h1> <input type="button" value="View All" class="form_button" style="float: right;" onclick="jrCore_window_location('{$jamroom_url}/{$_post.module_url}/uploaded_video');">          
        <div class="block_content">       
    {jrCore_list module="jrVideo" profile_id=$item._profile_id search1="video_file_item_price > 0" order_by="video_display_order numerical_asc" limit=$svl}
   </div>          
</div> 
{/if}

This is awesome - thanks so much Douglas.


--

Ken Rich
indiegospel.net
douglas
@douglas
8 years ago
2,791 posts
If the $item.sales_videos_limit variable is available in the template your jrCore_list call is in, then you don't need the capture part, you can just do this:

{if isset($item.sales_videos_limit) && $item.sales_videos_limit > 0}

<div class="title">        
         <h1>Video</h1> <input type="button" value="View All" class="form_button" style="float: right;" onclick="jrCore_window_location('{$jamroom_url}/{$_post.module_url}/uploaded_video');">          
        <div class="block_content">       
    {jrCore_list module="jrVideo" profile_id=$item._profile_id search1="video_file_item_price > 0" order_by="video_display_order numerical_asc" limit=$item.sales_videos_limit}
   </div>          
</div> 
{/if}

Hope this helps!


--

Douglas Hackney
Jamroom Team - Designer/Developer/Support
FAQ-Docs-Help Videos
Ken Rich
Ken Rich
@ken-rich
8 years ago
926 posts
Cool beans - even easier - thanks.

I almost blew a gasket when I looked at the first version and thought about the multiple foreach scenario - lol. I have never dealt with foreach assign or capture before.

I actually just finished my module. I got around the big issue of how to get the module URL to show my storefront on item_index.tpl and still be shareable with the proper OG metadata from the form.

I added a share button which opens the identical detail page, complete with share tools.

Go to http://kenrich.me/sales and click the green share button and see what happens.

It's a novel approach, I have to think outside of the box by nature because I don't understand the box - lol.


--

Ken Rich
indiegospel.net

updated by @ken-rich: 04/28/16 01:39:15PM