tags:

views:

136

answers:

2

Hi, on the site I'm working on, I need to show two different HTML snippets depending if another element is activated or not.

Like:

{if "div class="box expandResults" is enabled(or appearing on the page)"}

....HTML....

{else}

....OTHER HTML....

{/if}

How can I do this with Smarty or jQuery? I only have access to the .tpl files.

Thanks :)

+1  A: 

Well, you surely have some condition to make div class="box expandResults" appear on the page, so why not use the same one for this other case?

I the div in question is showed/updated via javascript (AJAX or something similar), then you can't do this with smarty alone.

jeanreis
It's all using Smarty to display the `div class...`, But I don't have access to the codes that enable it.
Kyle Sevenoaks
So you only have access to the .tpl files, is that it? You could try to figure out which variable/loop/whatever sets the div in question...Or is it the other way around, you only have access to the php side of things?? I'm confused..!
jeanreis
Sorry, I only have access to the .tpl files.
Kyle Sevenoaks
+1  A: 

Do it with JavaScript. Generate following HTML:

<div id="boxExpandResultsEnabled" style="visibility: hidden"> 
....HTML...
</div>
<div id="boxExpandResultDisabled" style="visibility: hidden"> 
....OTHER HTML....
</div>

JavaScript for Prototype would be:

<script>
        if($$('div.box expandResult')) {
            $('boxExpandResultsEnabled').show();
        } else {
            $('boxExpandResultsDisabled').show();
        };
</script>

Same thing for JQuery:

<script>
        if($('div.box.expandResult')) {
            $('#boxExpandResultsEnabled').show();
        } else {
            $('#boxExpandResultsDisabled').show();
        };
</script>
vartec
Maybe a better way to do it would be with jQuery? I already have a lot of jQuery on the site, another function can't hurt.
Kyle Sevenoaks
Ok, I've added JQuery, it's almost the same, except for the selectors
vartec