Plugin

Archived
Forum
(read-only)

Infinite Scroll

ExpressionEngine 1.x, ExpressionEngine 2

Back to this add-on's main page
View Other Add-ons From Laisvunas

     

Passing a category

Support Request

Guy
Guy

Trying to do something that seems like it should be relatively simple but is not quite working the way that I think it should, so I think I might be missing something. 

In my calling template I pass a category (or multiple categories) to the embed which contains the infinite scroll code.  So my calling template looks like this:

{embed="topics/ajax_archive" section_cat="50|53|2|1|49|51|52|48|47"

In the infinite scroll embed I have the following code:

{exp:infinite_scroll:wrapper ajax_container="ajax_container" category="{section_cat}" embed_template_url="{homepage}/topics/ajax_archive" process_indicator="process_indicator" next_chunk_link="next_chunk_link" parse="inward"}

 {infinite_scroll_container_top}
 
<div id="ajax_container">
 
{/infinite_scroll_container_top}
 
 
 {exp
:channel:entries channel="article" orderby="date" sort="desc" status="Open|Cover|Top News|Feature Lead|Opinion Lead|Travel Lead|More News" limit="15" paginate="bottom" dynamic="off" parse="inward" disable="categories|category_fields|member_data" category="{embed:section_cat}"}
   
  
<div class="entry">
   <
article>
    <
h2><a href="{title_permalink='article/'}">{title}</a></h2>
    
{exp:tagstripper:tagsToSave tags='p|a|b|switch|ul|li'}  
     {exp
:eehive_hacksaw  chars="250" append="..."}
      
<p>{article_body}</p>        
     
{/exp:eehive_hacksaw}
    {
/exp:tagstripper:tagsToSave}   
    
<ul class="articledetails">
     <
li class="author">{embed="includes/authors" entry_id="{entry_id}"}</li>
     <
li class="articlecomments"><span>{entry_date format="%F %d, %Y"}</span></li>
    </
ul>
   </
article>
  </
div>
  
  
{if count == total_results}
   
<div class="process_indicator">
    <
p style="padding-top:40px;">Loading...</p>
   </
div>
  
{/if}
  
 {paginate}{exp
:infinite_scroll:next_chunk_link}{if next_page}<a href="{auto_path}" class="next_chunk_link"><strong><div id="morebutton">More articles &raquo;</div></strong></a>{/if}{/exp:infinite_scroll:next_chunk_link}{/paginate}
 
 {
/exp:channel:entries}
 
 {infinite_scroll_container_bottom}
 
</div><!-- End of #ajax_container -->
 
{/infinite_scroll_container_bottom}

{
/exp:infinite_scroll:wrapper} 

The first set of results come back as planned and are properly narrowed by category, however when I click for more results I lose the category and embed variable (embed:section_cat) from the calling template is no longer passing the values. 

Looking at the documentation I see mention of ajax_pagination_vars and ajax_pagination_values and the mention of a complex example.  Perhaps I need to leverage these in some way but I don’t see sample code and I’m not clear on the usage based on the documentation. 

Anyway I think what I’m doing should be possible perhaps I have a simple mistake or am not understanding how variables are handled in the infinite scroll embed.

Thanks!

Guy

Guy
# 1
Guy

I decided to try something else based on your documentation for a similiar plugin, I tried this:

Calling template

{embed="topics/ajax_archive" ajax_pagination_vars="category" ajax_pagination_values="50"

Infinite Scroll template

{exp:infinite_scroll:wrapper 
 ajax_container
="ajax_container" 
 
embed_template_url="{homepage}/topics/ajax_archive" 
 
process_indicator="process_indicator" 
 
next_chunk_link="next_chunk_link"
 
ajax_pagination_vars=”{embed:ajax_pagination_vars}” 
 ajax_pagination_values
=”{embed:ajax_pagination_values}”
 parse
="inward"}


 {infinite_scroll_container_top}
 
<div id="ajax_container">
 
{/infinite_scroll_container_top}

 {exp
:channel:entries channel="article" orderby="date" sort="desc" status="Open|Cover|Top News|Feature Lead|Opinion Lead|Travel Lead|More News" limit="15" paginate="bottom" dynamic="off" parse="inward" disable="categories|category_fields|member_data" category="{ajax_pagination_embed_category}"}      
  
<p>Testing Variable {ajax_pagination_embed_category}</p>

  <
div class="entry">
   <
article>
    <
h2><a href="{title_permalink='article/'}">{title}</a></h2>
    
{exp:tagstripper:tagsToSave tags='p|a|b|switch|ul|li'}  
     {exp
:eehive_hacksaw  chars="250" append="..."}
      
<p>{article_body}</p>        
     
{/exp:eehive_hacksaw}
    {
/exp:tagstripper:tagsToSave}   
    
<ul class="articledetails">
     <
li class="author">{embed="includes/authors" entry_id="{entry_id}"}</li>
     <
li class="articlecomments"><span>{entry_date format="%F %d, %Y"}</span></li>
    </
ul>
   </
article>
  </
div>
  
  
{if count == total_results}
   
<div class="process_indicator">
    <
p style="padding-top:40px;">Loading...</p>
   </
div>
  
{/if}
  
 {paginate}{exp
:infinite_scroll:next_chunk_link}{if next_page}<a href="{auto_path}" class="next_chunk_link"><strong><div id="morebutton">More articles &raquo;</div></strong></a>{/if}{/exp:infinite_scroll:next_chunk_link}{/paginate}
 
 {
/exp:channel:entries}
 
 {infinite_scroll_container_bottom}
 
</div><!-- End of #ajax_container -->
 
{/infinite_scroll_container_bottom}

{
/exp:infinite_scroll:wrapper} 

This doesn’t work at all as {ajax_pagination_embed_category} doesn’t contain any data.  This should be simple what am I missing?

Thanks!

Guy

Laisvunas
# 2
Developer
Laisvunas

Hi Guy,

Apologies for the error in docs.

There is the following parameters of exp:infinite_scroll:wrapper tag:

1) infinite_scroll_vars
2) infinite_scroll_values

And to output variables defined using these parameters you should use the prefix “infinite_scroll_embed_”.

So, the code in main template should be:

{embed="topics/ajax_archive" infinite_scroll_vars="category" infinite_scroll_values="50"

The code in embed template should be:

{exp:infinite_scroll:wrapper 
 ajax_container
="ajax_container" 
 
embed_template_url="{homepage}/topics/ajax_archive" 
 
process_indicator="process_indicator" 
 
next_chunk_link="next_chunk_link"
 
infinite_scroll_vars=”{embed:infinite_scroll_vars}” 
 infinite_scroll_values
=”{embed:infinite_scroll_values}”
 parse
="inward"}


 {infinite_scroll_container_top}
 
<div id="ajax_container">
 
{/infinite_scroll_container_top}

 {exp
:channel:entries channel="article" orderby="date" sort="desc" status="Open|Cover|Top News|Feature Lead|Opinion Lead|Travel Lead|More News" limit="15" paginate="bottom" dynamic="off" parse="inward" disable="categories|category_fields|member_data" category="{ajax_pagination_embed_category}"}      
  
<p>Testing Variable { infinite_scroll_embed_category}</p>

  <
div class="entry">
   <
article>
    <
h2><a href="{title_permalink='article/'}">{title}</a></h2>
    
{exp:tagstripper:tagsToSave tags='p|a|b|switch|ul|li'}  
     {exp
:eehive_hacksaw  chars="250" append="..."}
      
<p>{article_body}</p>        
     
{/exp:eehive_hacksaw}
    {
/exp:tagstripper:tagsToSave}   
    
<ul class="articledetails">
     <
li class="author">{embed="includes/authors" entry_id="{entry_id}"}</li>
     <
li class="articlecomments"><span>{entry_date format="%F %d, %Y"}</span></li>
    </
ul>
   </
article>
  </
div>
  
  
{if count == total_results}
   
<div class="process_indicator">
    <
p style="padding-top:40px;">Loading...</p>
   </
div>
  
{/if}
  
 {paginate}{exp
:infinite_scroll:next_chunk_link}{if next_page}<a href="{auto_path}" class="next_chunk_link"><strong><div id="morebutton">More articles &raquo;</div></strong></a>{/if}{/exp:infinite_scroll:next_chunk_link}{/paginate}
 
 {
/exp:channel:entries}
 
 {infinite_scroll_container_bottom}
 
</div><!-- End of #ajax_container -->
 
{/infinite_scroll_container_bottom}

{
/exp:infinite_scroll:wrapper} 

 

Guy
# 3
Guy

I had actually tried something along these lines after I sent my support request, but it did not work.  I tried again based on the information you provided and it is still not working.  The variable doesn’t seem to get defined.  Here is what I have currently.

Calling page:

{embed="topics/ajax_archive" infinite_scroll_vars="category" infinite_scroll_values="50"

Infinite Scroll embed:

{exp:infinite_scroll:wrapper 
 ajax_container
="ajax_container" 
 
embed_template_url="{homepage}/topics/ajax_archive" 
 
process_indicator="process_indicator" 
 
next_chunk_link="next_chunk_link"
 
infinite_scroll_vars=”{embed:infinite_scroll_vars}” 
 infinite_scroll_values
=”{embed:infinite_scroll_values}” 
 parse
="inward"}


 {infinite_scroll_container_top}
 
<div id="ajax_container">
 
{/infinite_scroll_container_top}

 {exp
:channel:entries channel="article" orderby="date" sort="desc" status="Open|Cover|Top News|Feature Lead|Opinion Lead|Travel Lead|More News" limit="15" paginate="bottom" dynamic="off" parse="inward" disable="categories|category_fields|member_data" category="{infinite_scroll_embed_category}"}      
  
<p>Testing Variable {infinite_scroll_embed_category}</p>

  <
div class="entry">
   <
article>
    <
h2><a href="{title_permalink='article/'}">{title}</a></h2>
    
{exp:tagstripper:tagsToSave tags='p|a|b|switch|ul|li'}  
     {exp
:eehive_hacksaw  chars="250" append="..."}
      
<p>{article_body}</p>        
     
{/exp:eehive_hacksaw}
    {
/exp:tagstripper:tagsToSave}   
    
<ul class="articledetails">
     <
li class="author">{embed="includes/authors" entry_id="{entry_id}"}</li>
     <
li class="articlecomments"><span>{entry_date format="%F %d, %Y"}</span></li>
    </
ul>
   </
article>
  </
div>
  
  
{if count == total_results}
   
<div class="process_indicator">
    <
p style="padding-top:40px;">Loading...</p>
   </
div>
  
{/if}
  
 {paginate}{exp
:infinite_scroll:next_chunk_link}{if next_page}<a href="{auto_path}" class="next_chunk_link"><strong><div id="morebutton">More articles &raquo;</div></strong></a>{/if}{/exp:infinite_scroll:next_chunk_link}{/paginate}
 
 {
/exp:channel:entries}
 
 {infinite_scroll_container_bottom}
 
</div><!-- End of #ajax_container -->
 
{/infinite_scroll_container_bottom}

{
/exp:infinite_scroll:wrapper} 

In the output I get:

Testing Variable - {infinite_scroll_embed_category}

Where it should show the value.  When I add the variable (category=”{infinite_scroll_embed_category}) to the channel:enteries loop I get no results.  When I hard code it everything works fine so clearly the variable is not being properly passed.

Any thoughts?

Guy
# 4
Guy

Hold on… think I figured it out… when I copied and pasted from the sample code above the quotes were not plain quotes.  Turned on debugging and saw the issue.  So hopefully the issue is resolved.

Thanks!

Guy

Guy
# 5
Guy

Follow up question…

What I am trying to do is pass multiple categories in the value for a variable, so for example:

{embed="topics/ajax_archive" infinite_scroll_vars="category" infinite_scroll_values="50|53|2|1|49|51|52|48|47"

The intent is for category to have the value of “50|53|2|1|49|51|52|48|47”

But this is interpreted at category = 50 when processed because the way the pipe is used to implement the pairs.  So how can a variable have multiple values or how can the pipe be escape so that:

{exp:channel:entries channel="article" orderby="date" sort="desc" status="Open|Cover|Top News|Feature Lead|Opinion Lead|Travel Lead|More News" limit="15" paginate="bottom" dynamic="no" parse="inward" disable="categories|category_fields|member_data" category="{infinite_scroll_embed_category}"

Is seen as:

{exp:channel:entries channel="article" orderby="date" sort="desc" status="Open|Cover|Top News|Feature Lead|Opinion Lead|Travel Lead|More News" limit="15" paginate="bottom" dynamic="no" parse="inward" disable="categories|category_fields|member_data" category="50|53|2|1|49|51|52|48|47"

Rather than:

{exp:channel:entries channel="article" orderby="date" sort="desc" status="Open|Cover|Top News|Feature Lead|Opinion Lead|Travel Lead|More News" limit="15" paginate="bottom" dynamic="no" parse="inward" disable="categories|category_fields|member_data" category="50"

Hope this makes sense.

Thanks!

Guy

 

Laisvunas
# 6
Developer
Laisvunas

Hi Guy,

Install the version 1.1. In it I added the functionality of encoding pipe character inside the value of the parameter “infinite_scroll_values” by using the string :PIPE:

So, you code should be as this:

{embed="topics/ajax_archive" infinite_scroll_vars="category" infinite_scroll_values="50:PIPE:53:PIPE:2:PIPE:1:PIPE:49:PIPE:51:PIPE:52:PIPE:48:PIPE:47"
Guy
# 7
Guy

Thanks for adding this functionality!

Guy