I'm using CI Smarty
https://github.com/Vheissu/Ci-Smarty
There are Two issues with this as far as i have noticed. but the issue for which I opened this question is that I cant load a .tpl
file if that .tpl
file is inside the directory of another directory.
e-g this is my current directory structure for SmartyTemplate
--Themes
--SomeOtherThemeName
--Default //Default Theme Directory i am currently using
--css
--js
--images
--views
--admin (directory)
--sitesettings (directory)
--site-settings.tpl (template file) //This Template file will Not Work
If I move this Template file to parent directory which is admin
, it will work if i call it, but if i call it from inside sitesettings
directory it will not work.
Here how i call it.
function functionName(){
$data['title']="Some Title";
$this->parser->parse('admin/sitesettings/site-settings.tpl',$this->data);
}
Simply, Smarty Only Allow me to have 1 extra Directory in hierarchy under views folder, I want to know if there is any fix for this so that i can have unlimited or at least more directories in hierarchy so I don't have messed up file system.
update: if anyone wanna see my project coding please go to this github project.
https://github.com/pakistanihaider/HouseRentSystem
Database regarding this project.
http://www.mediafire.com/view/1jp9u906r8i10u0/houserentsystem.sql
NOTE: cant attach files here so uploaded the .sql
file on mediafire and added the link. If there is any rules against it, Admins sure can remove the link but please let me know the proper way of giving the file link.
Somehow found the main problem thanks to @Sauryabhatt.
I think problem exists in {{extends file='adminLayout.tpl'}}
how do it knows where the file exist, i mean if i move the file inside most inner directory how it will know where the main layout file exit to which it will be a child.? do i need to define a path when extending a file?
Update: Also Tried like to define the path to the layout, but seems that it also didnt worked out for me.
$this->parser->parse('extends:layouts/adminLayout.tpl|file:systemConfigurationSitePreferences.tpl',$this->data);
it works if i put the fail in admin directory, but stops working if i move the file inside in another directory of admin directory.
Change
into this
and
into this
then in your
site_helper.php
file define this codeand finally define your theme in the
MY_Controller
Then you are all done. Try and run the application. Hope it works for you now.
Checking the library, I think you should modify the file
libraries/MY_Parser
(https://github.com/Vheissu/Ci-Smarty/blob/master/libraries/MY_Parser.php) . There, you may find the following methods:When you invoke
parse
, it'll call_find_view
which load the paths from two places: In line 307, loadingwhere _template_locations is an array loaded in the method
_update_theme_paths()
in the line 375:and in line 314, with $new_locations:
I haven't tested it, sorry, but I think that if you add the path to your folders there, it'll find your files and you'll be able to increase your directory path. An improvement it'll be to add automatically your folder structure to the array in the method
_update_theme_paths()
, check: PHP SPL RecursiveDirectoryIterator RecursiveIteratorIterator retrieving the full tree and add it to_update_theme_paths()
, and it'll do it automatically, XDIf your smarty version is 2.1 or later there is no need to write directory name just file name is enough.
Use This
Instead of
Code of Frontend Controller
code of main.php index.php function
The answer seems to be very simple: a typo. You've written the path to the template file wrong. According to the directory structure you've presented you should have this:
Instead of this:
I've also done a quick CI setup with CI-Smarty to make sure and it works just fine with multiple subdirectories.
OMG, Aftr this long time, i tried almost everything, i even downloaded the zebra CMS to see why there code is working and not mine, xD i even tried changing there code with mine even knowing that it wont gonna solve anything but just was hoping. xD
But in the end finally i got my eyes on the Real Problem, When i tried to put the template file inside another directory of a directory the relative path got disturbed in admin layout.
I had some File Components like menus tabs in separate files which i was including in the Master Layout File. e-g:
so template was working if it was inside 1 directory but when i tried to add 1 more directory and put file inside it, the path gave error.
The Biggest Problem with CI Smarty is, it never gives error only give White Blank Page if there is any error regarding the tpl files.
If the error system would have been good i might would have found the solution faster.
Anyhow, now just Added the Base Path, so no matter how many directories i go in, it will not gonna give any problem..
Thanks for All your Support. Looks like my Bounty Got Wasted xD..