About PHP template Smarty of the primary use and experience sharing _php skills

Source: Internet
Author: User
Tags php template smarty template

As for how to configure, there is no more to say, a lot of online.
1. The most important approach to be used is the assign and display methods.
2. Basically the knowledge to be used on the page is the IF and foreach and section of the three.
3. Basically the hardest part is foreach and section.
4. Beginners always recycle the data they want. Because the feeling is still with PHP ah Java ah these foreach and for are somewhat different. It's hard to catch his path and it's hard to debug his data.
5. So here, I put a little bit of mindfulness out:
If the data is this way:

Copy Code code as follows:

Array (0=>array (' id ' => ' 1111 ', ' content ' => ' 2222 ')); then the Foreach Loop
{{foreach from= $exam item=item key=k}}
{{$item. Content}}
{{/foreach}}}

On it, but if it's array (' ID ' => ' 1111 ', ' content ' => ' 2222 '), then you can't cycle like this, you need to:
Copy Code code as follows:

{{foreach from= $exam item=item key=k}}
{{if $k eq ' content '}}
{{$item}}}
{{/if}}
{{/foreach}}}

If you do not know what the EQ means, you can search the Internet, below I give this to a little list:
EQ equals,
NE, neq are not equal,
GT greater Than,
Lt is less than,
GTE, GE is greater than equals,
LTE, le less than equal,
Not non, mod modulo.
is [not] a div by can be divisible by a number,
Is [Not]even is an even number,
$a is [not] even by $b i.e. ($a/$b)% 2 = 0,
is [not] odd is odd

6. In the Smarty template, if you want to use PHP code, this way:
{{php}} $a = ' Gayayang '; echo $a; {{/php}}}
This allows you to use the PHP code inside the template.

7. Referencing documents in Smarty:
Can use the above method: {{php}}include "config.php"; {{/php}}}
Or a professional one: {{include file= ' config.php '}}
All two methods can be implemented. The following more professional points, recommended.

8. One such method: $smarty->fetch ("mytemplate.html");
Both fetch and display are used for rendering templates. Fetch can assign the entire rendered template as a string to a variable that can be used to generate a static page

Now that you know how to use it, he can return the contents of the file to a variable, then this is very useful slightly. Oh
Using the FETCH function, you can assign a variable to the HTML that you want to output, and you can output some of the data in it.
The display method in the Smarty, which is actually called fetch, is just to show him directly, and fetch defaults to not display and returns to a variable.

Basically is so much, later have added to write again. Oh

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.