View previous topic :: View next topic |
Author |
Message |
toplisek Smarty Regular
Joined: 17 Sep 2009 Posts: 48
|
Posted: Fri Feb 17, 2017 11:11 am Post subject: Smarty detection for templates |
|
|
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 |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Fri Feb 17, 2017 2:28 pm Post subject: |
|
|
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 |
|
toplisek Smarty Regular
Joined: 17 Sep 2009 Posts: 48
|
Posted: Fri Feb 17, 2017 2:49 pm Post subject: |
|
|
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 |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Fri Feb 17, 2017 3:09 pm Post subject: |
|
|
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 |
|
bsmither Smarty Elite
Joined: 20 Dec 2011 Posts: 322 Location: West Coast
|
Posted: Mon Feb 27, 2017 7:55 pm Post subject: |
|
|
"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 |
|
sarahfoxnz Smarty Regular
Joined: 11 Apr 2010 Posts: 76
|
Posted: Sun Mar 12, 2017 9:52 pm Post subject: |
|
|
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 |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Sun Mar 12, 2017 10:19 pm Post subject: |
|
|
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 |
|
|