We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Prev / Next links for a Relationship column inside a Grid

How Do I?

RabRab's avatar
RabRab
5 posts
10 years ago
RabRab's avatar RabRab

I am using EE to display an online book, that is broken-down into

Volumes->Chapters->Pages

The way it’s structured, I have

Volume as a channel with 1 custom field “Chapters”, which is a Grid. Within this Grid are:

Chapter | Chapter URI | Pages

Pages is a Relationship to the channel Book_Pages. So in each ‘Pages’, there is a list of Book_Pages.

I’m at wits end trying to code “Previous” and “Next” links per chapter. The relationship within a grid is throwing me a curve ball. The Prev and Next shouldn’t be linking to whats prev/next in the actual Book_Pages channel, but within the Chapter->Pages list.

Hoping someone can provide me some guidance!

Thanks

       
RabRab's avatar
RabRab
5 posts
10 years ago
RabRab's avatar RabRab

So this is probably a total hack, and it’s not working yet, but I’m trying to use Stash to get the Prev and Next links

<!-- Previous/Next links - hacky -->
{exp:channel:entries channel="textbook" url_title="{segment_2}" dynamic="no"}
 {if no_results}
  {redirect="404"}
 {/if}  
  
 {tb_chapters}
  {if segment_3 == "{tb_chapters:chapter_uri}"} <!-- only worry about pages in current chapter -->

   <!-- setup loop-break variables -->
   {exp:stash:set}
    {stash:pn_finish}0{/stash:pn_finish}
    {stash:pn_active}0{/stash:pn_active}
   {/exp:stash:set}

    {tb_chapters:pages}
    
    {if "{exp:stash:get name='pn_finish' random}" == "0"} 
     -TEST-

     {if "{exp:stash:get name='pn_active' random}" == "1"} <!-- update NEXT page -->
      {exp:stash:set} 
          {stash:pn_next_title}{tb_chapters:pages:title}{/stash:pn_next_title}  
          {stash:pn_next_url_title}{tb_chapters:pages:url_title}{/stash:pn_next_url_title}
          {stash:pn_finish}1{/stash:pn_finish}
      {/exp:stash:set}
      
     {if:elseif segment_4 == "{tb_chapters:pages:url_title}"} <!-- active page -->
      {exp:stash:set name="pn_active"}1{/exp:stash:set}

     {if:else} <!-- update PREVIOUS page -->
      {exp:stash:set}
          {stash:pn_prev_title}{tb_chapters:pages:title}{/stash:pn_prev_title}  
          {stash:pn_prev_url_title}{tb_chapters:pages:url_title}{/stash:pn_prev_url_title}
      {/exp:stash:set} 
     {/if}  
     
    {/if}
    {/tb_chapters:pages}
    
  {/if}
 {/tb_chapters} 
{/exp:channel:entries}

{exp:stash:get name='pn_prev_title'}
{exp:stash:get name='pn_next_title'}

“-TEST-” only outputs one time however, which means it’s only entering the loop once? It should be looping through at least 4 times on the current page I’m on.

I’m still quite new to the world of EE - any advice would be much appreciated.

Thanks!

       
RabRab's avatar
RabRab
5 posts
10 years ago
RabRab's avatar RabRab

Here is my second hack attempt…still not working hah.

<!-- Previous/Next links - hacky -->
{exp:channel:entries channel="textbook" url_title="{segment_2}" dynamic="no"}
 {if no_results}
  {redirect="404"}
 {/if}  
  
 {tb_chapters}
  {if segment_3 == "{tb_chapters:chapter_uri}"} <!-- only worry about pages in current chapter -->

    {tb_chapters:pages}
    {if "{exp:stash:get name='pn_finish' default='0'}" == "1"} 
     DONE
     
    {if:elseif "{exp:stash:get name='pn_active' default='0'}" == "1"} <!-- update NEXT page -->
     NEXT
     {exp:stash:set name="pn_next_title"}{tb_chapters:pages:title}{/exp:stash:set}
     {exp:stash:set name="pn_next_url_title"}{tb_chapters:pages:url_title}{/exp:stash:set}
     {exp:stash:set name="pn_finish"}1{/exp:stash:set}
      
    {if:elseif segment_4 == "{tb_chapters:pages:url_title}"} <!-- active page -->
     ACTIVE
     {exp:stash:set name="pn_active"}1{/exp:stash:set}

    {if:else} <!-- update PREVIOUS page -->
     PREVIOUS
     {exp:stash:set name="pn_prev_title"}{tb_chapters:pages:title}{/exp:stash:set}
     {exp:stash:set name="pn_prev_url_title"}{tb_chapters:pages:url_title}{/exp:stash:set}
    {/if} 
    {/tb_chapters:pages}
    
  {/if}
 {/tb_chapters} 
{/exp:channel:entries}

{exp:stash:get name='pn_prev_title'}
{exp:stash:get name='pn_next_title'}
       
Aidan Dannevig's avatar
Aidan Dannevig
1 posts
5 years ago
Aidan Dannevig's avatar Aidan Dannevig

That’s cool!!! I am a fan of such materials and am learning to write myself. I am actively studying all aspects of this activity, at the same time studying history, writing articles. I recommend you my https://papersowl.com/examples/george-washington/ essays about George Washington. These are works on history, I am developing as an amateur, and I want to learn how to write professional works about information technology, programming and engineering circuits.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.