ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Jquery & Entry_Id?

February 18, 2012 11:49am

Subscribe [2]
  • #1 / Feb 18, 2012 11:49am

    jmorrison

    4 posts

    I have a show/hide Jquery function in place on a multi-entry page which toggles the visibility of extended content for each entry. It works nicely, however, when a “more” link is clicked it toggles the extended content for all entries simultaneously. I need to adjust the Jquery function to target each entry individually.

    The only method I can think of to achieve this is to have the Jquery function target EE’s {entry_id} parameter as part of the click event. This thread seems to imply that it would be possible to use the {entry_id} but I find I’m still struggling to figure out the syntax / implementation. Can anyone advise? Or set me straight if there is a better way?

    The Jquery is as follows:

    function showMore(){
    
    $('.more').hide();
    
    $('.morelink a').click(function(e) {
    $('.more').slideToggle('slow');
    $('.morelink a').toggleClass("less");
    $(this).text($(this).text() == 'Less' ? 'More' : 'Less');
    e.preventDefault();
    });
    }
    
    $(document).ready(function(){
    showMore();
    });

    This essentially looks for the click of a text link (.morelink a) and slidetoggles a hidden div (.more) while also toggles the text of said link from “More” to “Less” depending on the state. Note that this function, along with all of my Jquery, is located in a separate template which gets embedded on page load.

    The stripped down html in question is simply:

    {exp:channel:entries channel=“x” limit"x"}
    
    <div class=“content”>content</div>
    <div class="more">more content</div>
    <div class="morelink"><a href="#">More</a></div>
    
    {/exp:channel:entries}

    Any and all guidance is GREATLY appreciated.

     

  • #2 / Feb 18, 2012 12:18pm

    Bhashkar Yadav

    727 posts

    i think, you should follow method like :

    1) create a new template like new_template. put the channel entry tag with entry_id=”{segment_3}”
    2) create an url like /template_group/new_template/{entry_id}
    3) while click at MORE, use jquery load API to load content into div like $(”#DIV_ID”).load(’/template_group/new_template/{entry_id}’); and now toggle the div.

    i hope, this would help you.

  • #3 / Feb 18, 2012 1:23pm

    jmorrison

    4 posts

    Thanks for the thoughts Bhashkar.

    I always appreciate someone taking the time to respond on these increasingly quiet Community Support forums. Truly.

    That being said, I was really hoping to solve this within the structure I’ve already put in place and only resorting to the kind of serious structural reorganization you suggest if absolutely necessary.

    I feel like a show/hide on a multi entry page must be a relatively common UI choice, no?

  • #4 / Feb 18, 2012 1:26pm

    jmorrison

    4 posts

    edit

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases