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

Smarty detection for templates

 
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 -> General
View previous topic :: View next topic  
Author Message
toplisek
Smarty Regular


Joined: 17 Sep 2009
Posts: 48

PostPosted: Fri Feb 17, 2017 11:11 am    Post subject: Smarty detection for templates Reply with quote

I lke to set init function based on template detection. Template detection is actually current template file using $smarty.template.

How to achieve result using standard smarty function. Example is the following:

Code:
{if $smarty.template == Mytemplatefile.tpl}
{nocache}
{literal}
<script>

</script>
{/literal}
{/nocache}
{/if}


Need help how to do in the correct way. Javascript file should not be shown if there is other tpl file.

Need help.[/code]
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Fri Feb 17, 2017 2:28 pm    Post subject: Reply with quote

That makes no sense. How could it be that you render something.tpl, but instead it suddenly renders somethingelse.tpl ?
Short version is that you don't need to do that.
Smarty always do what you ask it to do. There's no sense in such tests.
Back to top
View user's profile Send private message
toplisek
Smarty Regular


Joined: 17 Sep 2009
Posts: 48

PostPosted: Fri Feb 17, 2017 2:49 pm    Post subject: Reply with quote

I have to detect URL page name and compare it if this is requested page.

If I detect tpl name and it is true I can publish Javascript only on tpl files that are validated as true. In this case I do not need to publish Javascript function on all pages as it will post an error. It will init function only on particualr tpl files.

Which smart standard function is possible in this case and the correct IF sentence.
My file is somethingelse.tpl

Need help.
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Fri Feb 17, 2017 3:09 pm    Post subject: Reply with quote

toplisek wrote:
I have to detect URL page name and compare it if this is requested page.

That's irrelevant.
This is not a Smarty question, this is PHP (your code) question.
Back to top
View user's profile Send private message
bsmither
Smarty Elite


Joined: 20 Dec 2011
Posts: 322
Location: West Coast

PostPosted: Mon Feb 27, 2017 7:55 pm    Post subject: Reply with quote

"I have to detect URL page name"

The name of the template being worked on is self evident. If Smarty is compiling "somethingelse.tpl", then that's it's name. It won't have any other name.

But if you really want the URL, or perhaps some other identifier, then there are $smarty Request Variables, and if you are putting dynamic content in a superstructure, the superstructure can test for the type of dynamic content:
Code:

{if $PAGE_TYPE eq "contact"}
<!-- stuff just for the Contact Us page -->
{/if}
Back to top
View user's profile Send private message
sarahfoxnz
Smarty Regular


Joined: 11 Apr 2010
Posts: 76

PostPosted: Sun Mar 12, 2017 9:52 pm    Post subject: Reply with quote

From what I gather, the question is this

Smartytemplate1.tpl
Smartytemplate2.tpl
Smartytemplate3.tpl
Smartytemplate4.tpl

are all separate tempaltes, but they all INCLUDE another template.

includedtemplate.tpl. They want the included template to know which main template called it.

you could use the assign function - assign a name in your main tempaltes, & in the included tempalte, detect that assigned name & do something.

is that whats needed ? or the original query ?
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Sun Mar 12, 2017 10:19 pm    Post subject: Reply with quote

I said that already: there must be no situation, where this information would be necessary.
If you have such a "need", you should rethink your template structure. Because there's a high chance you're doing something terrible wrong.
Back to top
View user's profile Send private message
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 -> General 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