• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CI with Smarty - Problems with Included content...

#1
[eluser]Myles Wakeham[/eluser]
I use Smarty with CI and have for a while. It has been working fine for me on some big applications, however recently I started to notice on a new application I was working on that about 5% of the time, I found that it would not resolve Smarty tags when working with CI.

I found that if I removed the compiled Smarty template content on the server (templates_c folder content) and started again, it was fine for a while but eventually would return to similar behavior. So I have spent the past few hours digging deep to find out what is going on. I've found some interesting things....

Smarty has a wonderful tag that can be inserted into a template file called {include file="xxxxxx"} where you have force Smarty to include the block into the template file before it is sent out to the browser. This is great for design, as it allows one to break up a web page into segments and deal with the segments separately.

However this seems to be the culprit with CI. If I use this command to combine all the blocks together, I find that the original master TPL file that contains the {include file="xxxxxx"} statements won't resolve the tags in the master TPL file, but will resolve the tags in the included block. Again, this only occurs about 2% of the time.

It would appear that it has something to do with the way that CI is caching the content and interfering with Smarty. I have other applications that have been in production for years that use CI & Smarty and they work perfectly. However the main difference is that they don't use the {include file="xxxxxxx"} statement at all.

So before I go through literally 50 TPL files and force them to include the actual blocks in the master TPL files, I wanted to reach out to the CI community and see if anyone else had experienced what I am describing. If so, out of interest are you using {include file="xxxxxx"} statements in your TPL files? If you were able to get around this issue, what's the secret?

Here's a screenshot of the end result of this problem if anyone is interested:

SCREENSHOT

Thanks in advance for any feedback.

Myles

#2
[eluser]Unknown[/eluser]
Did you ever come up with a solution to this? We are having a similar problem with smarty causing problems 2% of the time.

Thanks!

#3
[eluser]Myles Wakeham[/eluser]
[quote author="puck916" date="1214260102"]Did you ever come up with a solution to this? We are having a similar problem with smarty causing problems 2% of the time.[/quote]

Yes and no. I found somethings I can do in the HTML that helped, but I'm not sure I really got to the bottom of why this was happening. Here's what I did discover that made a difference:

1. The templates_c folder that Smarty uses to cache the template files has a lot to do with this. I thought I had specifically told Smarty to not cache the pages, but what I found was that if I manually clear out this folder, then it worked fine. So the problem definitely has something to do with Smarty caching and CI use of Smarty.

2. We use 'Blocks' for our pages, so that there is a standard header & footer, but the block is dynamically included through a Smarty Include statement. I was having issues with Block development (which we do in Dreamweaver) because of CSS references that were in the block that also were in the header. The <LINK> tags were being repeated, which was forcing the browsers to request CSS included files multiple times. When I removed all CSS referencing from within the Blocks, this dropped the number of issues down dramatically.

3. We have another heavily used site (http://www.cyberears.com) that has been in production for about 3 years, and uses CI and Smarty. Never a problem there. The difference between the newer sites we're developing and CyberEars.com is the block inclusion. In CyberEars.com we never used block inclusion, and consequently never had a problem with Smarty Caching. But in this new application, we use block inclusion on every page, which is why for a small percentage of time, the Smarty caching is failing.

I'm also not sure that its consistent between all browsers. I bring this point up simply because we only use Firefox in development, and that's where it seems to show up. It may not show up in IE, and that could have something to do with the speed that the browsers are requesting the pages. But again, I fall back to the issue of Block inclusion and Smarty caching being the main culprit here.

I've posted on Smarty forums and not really had any direction from that. The fact that we have other sites in production that work perfectly with CI and Smarty tells me that the problem has something to do with block inclusion.

Myles


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.