search
Homephp教程php手册php Smarty初体验二 获取配置信息_php模板_脚本之家

Smarty模板的特性决定了它的优越性,更是PHPer追捧的原因之所在(更多的是招聘的大部分都要求),今天大致看了Smarty的基本使用方法,不过光看也没用,中午没事随便试了试,结果就一个小问题却导致我中午没了睡觉的时间了

先看结果——

  页面源代码如下:

  分析一下代码,经过检查index_config.php(Smarty连接文件)、index.php文件均无错,下面重点看看模板文件,可能原因就出在这个tpl文件上,出代码——
代码如下:
{% config_load file="1.conf" section="style2" %}



{% #title# %}

{%$hello%}
{%*这是一个注释语句*%}


{%$array.0.0%}



Smarty不能将模板文件中的变量解析成相应的值,肯定是调用文件时的错误了,但看着写的代码也没错啊,和书上的、网上的几乎一模一样的,怎么会出错呢??

  百思不得其解之际,突然发现,在调用变量时自己的代码比他们多了空格…………………………

  删除空格,大功告成:

  页面源代码

  总结,在使用Smarty模板时,不要为了代码的美观和可读性而增加空格,这样Smarty不会把这些当成变量解析的,而会直接输出

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor