Knowing how many times a module has been used in a template…
Posted: 31 August 2008 12:46 PM   [ Ignore ]  
Summer Student
Total Posts:  19
Joined  08-19-2008

Howdy,

I’m working on developing a Google Maps plug-in, which is working quite well. What I currently need, though, is some way to know how many times my module has been called on the same page. I’ve searched this site all through, and haven’t found a thing.

The general gist is this:

{exp:mapper id="testMap1"}

{exp
:mapper id="testMap1"}

{exp
:mapper id="testMap2"}

I want to know, when the mapper module is called, how many times it’s been previously run.

Perhaps a global of some kind? I tried declaring one, but it didn’t seem to persist.

Thanks for the input!

-Daniel

Profile
 
 
Posted: 05 September 2008 12:33 PM   [ Ignore ]   [ # 1 ]  
Summer Student
Total Posts:  19
Joined  08-19-2008

No ideas?

-Daniel

Profile
 
 
Posted: 05 September 2008 03:16 PM   [ Ignore ]   [ # 2 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  719
Joined  07-02-2007

You could make a counter in the $SESS->cache

if isset($SESS->cache['mapper']['count'])
{
$SESS
->cache['mapper']['count'] = $SESS->cache['mapper']['count'] + 1;
}
else
{
$SESS
->cache['mapper']['count'] = 1;
}

In every module call you can check that to see how many times smile

 Signature 

Truly ExpressionEngine


Fielder Module ( Mass Custom Fields )
Super Cache (Cache heavy tag output)
reCAPTCHA Extension
Rewrite Module


See all my EE Addons (8)

Profile
 
 
Posted: 05 September 2008 03:34 PM   [ Ignore ]   [ # 3 ]  
Summer Student
Total Posts:  19
Joined  08-19-2008

Ok, now I just feel dumb. That makes perfect sense!

Thanks, Victor!

-Daniel

Profile
 
 
Posted: 06 September 2008 03:49 PM   [ Ignore ]   [ # 4 ]  
Summer Student
Total Posts:  19
Joined  08-19-2008

New question.

So I’m trying to write out JavaScript code, but on every additional call of the module, I need to modify some early written/rendered output. Any thoughts on how to do this? I’m searching through the documentation looking for a way to access previous output, but no luck yet.

If I knew when the last time my module would be called is, I could just create my final Javascript code version during that time.

The code looks something like:

<script type="text/javascript">
function
init()
{
Drawbox
("div1");
Drawbox("div2");
Drawbox("div3");
}
</script>

When my first call comes along, it would output this:

<script type="text/javascript">
function
init()
{
Drawbox
("div1");
}
</script>

Second time:

<script type="text/javascript">
function
init()
{
Drawbox
("div1");
Drawbox("div2");
}
</script>

And the third time would be like I first showed the example.

I’m not sure I can do that. hmmm

I’m going to look into some JavaScript get workarounds for now. smile

Thanks!

-Daniel

Profile
 
 
Posted: 06 September 2008 03:58 PM   [ Ignore ]   [ # 5 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  719
Joined  07-02-2007

The $TMPL is your friend smile

global $TMPL;

// The current template
print_r($TMPL->template);

// The final rendered template
print_r($TMPL->final_template);

 Signature 

Truly ExpressionEngine


Fielder Module ( Mass Custom Fields )
Super Cache (Cache heavy tag output)
reCAPTCHA Extension
Rewrite Module


See all my EE Addons (8)

Profile
 
 
Posted: 06 September 2008 05:46 PM   [ Ignore ]   [ # 6 ]  
Summer Student
Total Posts:  19
Joined  08-19-2008

Awesome, Victor! Thanks!

Now I’m curious where in the documentation those functions were mentioned… I’ve been all through the template parser class documentation… I didn’t see those there. hmmm

Thanks again.

-Daniel

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 65085 Total Logged-in Users: 32
Total Topics: 82222 Total Anonymous Users: 17
Total Replies: 441913 Total Guests: 224
Total Posts: 524135    
Members ( View Memberlist )
Newest Members:  BombermanhaimtuagocsadamVeNeaDoRHildegaardhrtrulzUNFORGIVEN IIIEmmanuelYanYanTomsB