Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Smarty Templates Location
zhlousek
New
Hi,
Very simple question, I hope.
I would like to use Smarty include file='....' in a theme I am using.
After looking through a compiled template it appears that this is not something disabled.
I haven't been able to figure out where to put the template file I'd like to include. Most obvious places, theme view folder does not appear to work nor it does inclusion using the file system absolute path or relative to site doc root.
I would appreciate is someone knows where template files can be placed.
I know that this can be set in the Smarty class itself but I was unable to find the location in the version of Smarty used by Vanilla.
Thanks
0
Comments
view/default.master.tpl
that is the only smarty file.grep is your friend.
Thanks,
I know that.
I'd like to put an include file line into view/default.master.tpl so that I have
{include file='myfile.tpl'}
I need this flexibility to make changes depending on some condition (yes I am using Vanilla for something it was not designed to do but it's working well, mostly, as always).
Question I was asking is - where do I put myfile.tpl so that it is read. Few obvious locations I tried do not work.
Sorry this feature is disabled. It is not possible to do it like this directly.
You have the option of creating theme hooks.
You can create a module (in php) that can be loaded in you template file.
Another possibility it to create a function an load it as a smarty function then you can use it in your template. You could even get it to load a template file.
You can also file custom event, which you then hook in you themehoook file, and do whatever with.
grep is your friend.
OK,
Thanks for the answer.
Too bad. Include is a simple solution for some situations.
I know I can create a module or create a function. Both seem an overkill for my need.
There are other ways too.
Thanks again.
@zhlousek:
What I've done a couple of times to compensate for the missing
includes
is to store my template partials within variables like this:This will fetch the
YourTheme/views/partials/footer.tpl
andYourTheme/views/partials/header.tpl
partials and make them available to your master view through the$_Partials
variable like this:Not optimal, but it's easy and it works!
Kasper Kronborg Isager (kasperisager) | Freelance Developer @Vanilla | Hit me up: Google Mail or Vanilla Mail | Find me on GitHub
we have given you about 4-5 different ways to do it.
I think the event way is quite good, although kasperisager's way is equally valid.
I think it is better to use the template to
yield
rather that having includes directly in the template.grep is your friend.
Thanks a lot.
This is an excellent idea.
I very much appreciate all replies. This is a great community.
Just for future reference: The Smarty
{include file="..."}
tag should now work like it's supposed to so there's no need for the rather awful looking workaround I came up with.Kasper Kronborg Isager (kasperisager) | Freelance Developer @Vanilla | Hit me up: Google Mail or Vanilla Mail | Find me on GitHub
way to go, kasper on the cutting edge!
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
Hehe, working at the Montreal office has its benefits
Kasper Kronborg Isager (kasperisager) | Freelance Developer @Vanilla | Hit me up: Google Mail or Vanilla Mail | Find me on GitHub