Topics

uniqueid function

Unique ID will cause Exponent to generate a unique identifier for you on the fly. This can be used with TPLs that have a depending javascript file.  You can set a prefix by passing the 'prepend' parameter or have the id assigned to a variable by passing the 'assign' parameter.  If you have multiple instances of the same script being used on the same page, you will avoid errors by doing the following:

<div id="carousel-container{uniqueid}">
  
  <div id="container{uniqueid}">

      <ol id="carousel{uniqueid}">
      
         {if $items|@count gt 0}
           {foreach from=$items item=text name=items}
             <li class="item">
               {if $text->title}<h2>{$text->title}</h2>{/if}
               {bodycopy}
             </li>
           {/foreach}
         {/if}

      </ol><!-- end carousel -->

  </div> <!-- end carousel -->

</div> <!-- end carousel containter -->


{script unique="yuicarousel`uniqueid`" yuimodules="carousel,animation"}
{literal}

    YAHOO.util.Event.onDOMReady(first);
    
           var carousel;
                
       function first () {
            var carousel    = new YAHOO.widget.Carousel("container{/literal}{uniqueid}{literal}", {
                        animation: { speed: 1.0, effect:YAHOO.util.Easing.easeOut},

   <!-- other carousel params -->
   <!-- other carousel params -->
   <!-- other carousel params -->

{/literal}
{/script}

In the javascript snippet at the bottom of your TPL, you will have to break out of the "literal" tag for a moment and introduce a "uniqueid".  Look carefully and you will see what we are doing.  We are applying a uniqueid to the div names, and to the references in the javascript, so they point to the same thing.  In the end, if the view is used multiple times on the page, there will be no javascript errors because of the unique id.  Efficient code reuse.

Loading Help