Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

something like is_included function?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty Development
View previous topic :: View next topic  
Author Message
himerus
Smarty Rookie


Joined: 25 Oct 2004
Posts: 12
Location: Denver, CO

PostPosted: Thu Feb 24, 2005 7:44 pm    Post subject: something like is_included function? Reply with quote

I'm just looking for something that will be either called from smarty or from my PHP file in a footer section that will determine if a specific template file/files have been included earlier in the page, and if it has, it should add an aditional template to the footer, or simply, assign a variable specifying such..

Example... template A is a custom template that may or may not include another template inside of it...

Template A:
text
text
text
<!--{include file="templateb.tpl"}-->
text
text
text


I need to determine if the templateb.tpl has been included at the end of my script. If it was done inside smarty, it would simply add another line of html, or if from PHP, it would assign a variable that would be handled in the footer...

I didn't see anything right off from searching, or in the documentation...

I'm sure it's an easy solution, TIA for advice.
_________________

Credit Repair | Mortgage & Refinancing | Bankruptcy | Debt Relief | Loans
Back to top
View user's profile Send private message Visit poster's website
himerus
Smarty Rookie


Joined: 25 Oct 2004
Posts: 12
Location: Denver, CO

PostPosted: Thu Feb 24, 2005 7:48 pm    Post subject: clarification.... Reply with quote

for some clarification, what I need is to know if a certain template or template has been called ANYWHERE throughout the page that has been compiled...

it would be called last, and display custom content dependant on if the template in question has been called.
_________________

Credit Repair | Mortgage & Refinancing | Bankruptcy | Debt Relief | Loans
Back to top
View user's profile Send private message Visit poster's website
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Thu Feb 24, 2005 8:41 pm    Post subject: Reply with quote

Could you do something like:

$smarty->assign('include_b', true);

Then in the templates:

{if $include_b}{include file="template_b.tpl"}{/if}

{if $include_b}do footer logic here{/if}

In other words, don't rely on testing if a template got included, instead have your template behaviors act upon an explicitly assigned value, which includes template inclusion and footer text.
Back to top
View user's profile Send private message Visit poster's website
himerus
Smarty Rookie


Joined: 25 Oct 2004
Posts: 12
Location: Denver, CO

PostPosted: Fri Feb 25, 2005 1:19 am    Post subject: Reply with quote

mohrt wrote:
Could you do something like:

$smarty->assign('include_b', true);

Then in the templates:

{if $include_b}{include file="template_b.tpl"}{/if}

{if $include_b}do footer logic here{/if}

In other words, don't rely on testing if a template got included, instead have your template behaviors act upon an explicitly assigned value, which includes template inclusion and footer text.


The only reason I'm not taking that option at the moment is that this is part of a content managment system, and the template A mentioned above is the editable content that a user is able to make changes to, and the user has the option to include an advertisement plugin template in the content of the template they are creating with the editor.

If the user has included the template in the content, then, I need to include another template that has tracking features for the template that the user included in thier content template...

I'm not sure if this makes a ton of sense...

if there were something that was like the is_cached function, that just noted that a template had been loaded for that page...

If I use something like what is mentioned above, then I'm no longer giving the user the ability to place the advertisement template anywhere they want in the content page template code. It seems minimal, but is an important requirement for the system users.
_________________

Credit Repair | Mortgage & Refinancing | Bankruptcy | Debt Relief | Loans
Back to top
View user's profile Send private message Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Fri Feb 25, 2005 2:02 am    Post subject: Reply with quote

The problem I see is that Smarty doesn't really know. Smarty doesn't make any attempt to keep or record the internal structure of a template.

There may be better ideas out there but one thing you can consider is using a prefilter. Prefilters allow you to modify the template sourcecode before it is processed by Smarty. In practice, you would have your prefilter scan the template sourcecode for {include} tags that match your criteria. You could then do something to match your needs, either insert an additional {include} tag for your tracking template in-place or set some global variable with a status indicator of some sort -- or what-have-you. You'll have to roll up your sleeves some but it might do the trick.

On-the-other-hand, you would likely be way better-off writing a custom plugin function for those special types of includes. You could still accept the 'file' parameter and your function could fetch the template and return it along with doing whatever other processing and/or appending any other data that it involves.

Yet another idea is to provide a custom resource that would potentially concatenate two templates if the requested path matched your criteria. You could then set this as the default resource type if you wanted that behaviour always.

One last thing I can think of is to override smarty::_include() -- but that's crazy talk.
Back to top
View user's profile Send private message
himerus
Smarty Rookie


Joined: 25 Oct 2004
Posts: 12
Location: Denver, CO

PostPosted: Fri Feb 25, 2005 4:51 pm    Post subject: Reply with quote

Okay, my solution is this... I've added a function into the smarty core that caches the template names that have been called in an array, where I can call that with my php script later, and take action if needed, not just on this situation, but with others I may need to be aware of templates being dynamically called throughout the called page.

I have everything working except I'm not sure which part of the smarty core is including files that have been included in a template, and not called from PHP. It is working properly for any template called using fetch() or display(), but where in the core files are that scan and include these sections? {include file=""}
_________________

Credit Repair | Mortgage & Refinancing | Bankruptcy | Debt Relief | Loans
Back to top
View user's profile Send private message Visit poster's website
himerus
Smarty Rookie


Joined: 25 Oct 2004
Posts: 12
Location: Denver, CO

PostPosted: Fri Feb 25, 2005 4:58 pm    Post subject: Reply with quote

nevermind, I found it in _smarty_include
_________________

Credit Repair | Mortgage & Refinancing | Bankruptcy | Debt Relief | Loans
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty Development All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP