3 quick tips for using Smarty to improve your site.

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Post Reply
psy
Power Poster
Power Poster
Posts: 463
Joined: Sat Jan 22, 2005 11:19 am

3 quick tips for using Smarty to improve your site.

Post by psy »

Tip 1: Compressing CSS on the fly
I'm loving the ScriptDeploy module however sometimes it's overkill. Now that the {cms_stylesheet} tag supports Smarty, put:

[[strip]] at the start and [[/strip]] at the end of your CSS file and guaranteed, your page will load more quickly!

Tip 2: My friend the Smarty replace modifier
Often in module templates things such as input field sizes, return pages, etc are dictated by the module action. Rather than change the action php code, I use, eg:

{$input_fieldname|replace:'size="80"':'size="40"'}

Returns the result I need without resorting to javascript, messing with CSS or tampering with the original module php files.

Tip 3: Using Smarty to 'test' for javascript
I had a page that was rather large and used jQuery UI tabs in the content. Problem was that for browsers that supported javascript, there was a visible jump between the page load and the $(document).ready stuff when the tabs kicked in.

Part of the solution was to add the 'accessibility' class to the content container div and remove it with jQuery when the page was ready. Worked well, the page literally flashed onto the screen already formatted. Problem was that browsers that did not support javascript would simply see the background. Solution was to add:

Code: Select all

{capture assign=accessibility}<__script__ type="text/javascript">var x = ' class="accessibility";return x;'{/capture}
in the page head section. My jQuery script is at the bottom of the page so no reference to it here.

In the content area:

Code: Select all

<div id="pagewrapper" {$accessibility}>
and in my jQuery statement:

Code: Select all

$(document).ready(function(){
  $('#pagewrapper').removeClass('accessibility');
});
Now only browsers that support js will have the beautiful tabs, those that don't only see the pure HTML page.


HTH,
Cheers
psy
User avatar
manuel
Power Poster
Power Poster
Posts: 353
Joined: Fri Nov 30, 2007 9:15 am

Re: 3 quick tips for using Smarty to improve your site.

Post by manuel »

thx for the replace modifier tip! can't wait to try it!

Greetings,
Manuel
psy
Power Poster
Power Poster
Posts: 463
Joined: Sat Jan 22, 2005 11:19 am

Re: 3 quick tips for using Smarty to improve your site.

Post by psy »

My plez Manuel, it's certainly saved me a lot of time and heartache.

;) psy
lucy
Forum Members
Forum Members
Posts: 48
Joined: Tue Jun 29, 2010 9:59 am

Re: 3 quick tips for using Smarty to improve your site.

Post by lucy »

Hey seems to be very good tipps. Re Tip2: where do you put this line? In the Module Template? I didn't get it to work yet...
psy
Power Poster
Power Poster
Posts: 463
Joined: Sat Jan 22, 2005 11:19 am

Re: 3 quick tips for using Smarty to improve your site.

Post by psy »

Hi lucy

The replace modifier (or any smarty modifier) can be used on any tag in your templates.

The replace modifier will replace the tag's default output with whatever you choose.

Firstly, use the tag as normal and output the page, eg {mytag}. Next, look at the html code and find the text string to replace. Copy/paste that in the first option and your new text in the second option, eg:

{mytag|replace:'put the original string here':'put your replacement text here'}

As uniqu3 suggests, the best place to start is to read the smarty documentation.

cheers
psy
FletcherT
New Member
New Member
Posts: 3
Joined: Tue Jul 26, 2011 8:00 pm

Re: 3 quick tips for using Smarty to improve your site.

Post by FletcherT »

Oh man, the replace modifier suggestion, thanks!

-Fletcher
dwave
Forum Members
Forum Members
Posts: 39
Joined: Mon Aug 13, 2007 11:15 am
Location: Israel

Re: 3 quick tips for using Smarty to improve your site.

Post by dwave »

The replace modifier is also an uncomplicated way to force submits of forms always to use SSL.

Just put this in your form template instead of {$fb_form_start}:

Code: Select all

{$fb_form_start|replace:'http':'https'}
Post Reply

Return to “Tips and Tricks”