Home Backend Development PHP Tutorial smarty 列表插件显示标题长度和连接解决思路

smarty 列表插件显示标题长度和连接解决思路

Jun 13, 2016 pm 01:42 PM
empty length quot smarty

smarty 列表插件显示标题长度和连接
现在在写一个站, 要在smarty 插件那里写一个列表插件,要截取标题长度。

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--><?php function smarty_function_list($params, &$smarty)
    {
        extract($params);
        $cate = !empty($cate) ? trim($cate) : '';//表名
        $items = !empty($items) ? trim($items) : '*';//字段
        $length=!empty($length) ? trim ($length) :'10';//长度
        $where = !empty($where) ? trim($where) : '';//条件
        $order = !empty($order) ? trim($order) : '';//排序
        $page = !empty($page) ? intval($page) : 0;//分页
        $pagesize = !empty($pagesize) ? intval($pagesize) : 20;
        $varname = !empty($varname) ? trim($varname) : '';

        global $db;
        global $table;
        $sql="select $items from ".$table[$cate];
        if(!empty($where))
        {
            $sql.=" where $where ";
        }
        if(!empty($order))
        {
          $sql.=" order by $order";
        }
        $page=max($page,1);
        if($pagesize<1)
        {
            $pagesize=10;
        }
        $rs=$db->PageExecute($sql,$pagesize,$page);
        $rs=$rs->getRows();
        $smarty->assign($length,$length);
        $smarty->assign($varname, $rs);
        unset($rs);
    }
?>

Copy after login

上面是插件代码;
HTML code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
{--list cate="articles" items="Title" length=4 varname="rs"--}
{--foreach from=$rs item=r--}
{--$r.Title--}<br>
{--/foreach--}

Copy after login

上面是模板代码。
现在就是要截取标题长度,和标题连接
$r.Titletruncatecn:$length:"...":true
这种的是不行的!各位师兄,师姐谢谢了!

------解决方案--------------------
探讨

$length是哪里来的?

如果是变了的话,试下这个呢
$r.Title|truncate:`$length`:"...":true
要不就指定一个具体数字
$r.Title|truncate:30:"...":true
Statement of this Website
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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Use java's String.length() function to get the length of a string Use java's String.length() function to get the length of a string Jul 25, 2023 am 09:09 AM

Use Java's String.length() function to get the length of a string. In Java programming, string is a very common data type. We often need to get the length of a string, that is, the number of characters in the string. In Java, we can use the length() function of the String class to get the length of a string. Here is a simple example code: publicclassStringLengthExample{publ

PHP determines whether a specified key exists in an array PHP determines whether a specified key exists in an array Mar 21, 2024 pm 09:21 PM

This article will explain in detail how PHP determines whether a specified key exists in an array. The editor thinks it is very practical, so I share it with you as a reference. I hope you can gain something after reading this article. PHP determines whether a specified key exists in an array: In PHP, there are many ways to determine whether a specified key exists in an array: 1. Use the isset() function: isset($array[&quot;key&quot;]) This function returns a Boolean value, true if the specified key exists, false otherwise. 2. Use array_key_exists() function: array_key_exists(&quot;key&quot;,$arr

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 Jun 13, 2016 am 10:23 AM

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

How to use PHP and Smarty to achieve front-end and back-end separation development How to use PHP and Smarty to achieve front-end and back-end separation development Jun 25, 2023 pm 01:46 PM

In modern web development, the separation of front-end and back-end has become a very popular trend, which allows developers to better organize projects and improve the efficiency of project development. PHP and Smarty are two very commonly used technologies, which can be used to achieve front-end and back-end separation development. This article will introduce how to use PHP and Smarty to achieve front-end and back-end separation development. What is front-end and back-end separation development? In traditional web development, the front-end is mainly responsible for the presentation of the page and the logic of interaction with the back-end. The backend is mainly responsible for the business

A preliminary study on the template engine Smarty in PHP A preliminary study on the template engine Smarty in PHP May 11, 2023 pm 05:15 PM

Nowadays, website development is inseparable from an important component-template engine. A template engine refers to a tool that combines page templates and data to generate HTML code with a specific format. In various website development frameworks, the template engine is an essential component, because the template engine can greatly reduce the duplication of code and improve the dynamics of the page. One of the most common and popular template engines is Smarty. Smarty is a DSL (DomainSpecif

How to use Smarty template engine in PHP development How to use Smarty template engine in PHP development Jun 27, 2023 pm 01:28 PM

As a PHP developer, using a template engine is a natural choice. Smarty is a popular template engine that provides a way to separate HTML/CSS/JavaScript from PHP code, allowing developers to better organize and manage projects. In this article, we will learn how to use Smarty template engine during PHP development. 1. Install Smarty Before, we must install Smarty. In this article we will use Composer to install

How to use PHP and the Smarty template engine How to use PHP and the Smarty template engine May 11, 2023 pm 03:33 PM

PHP is a powerful server-side scripting language that can be used to develop web applications. In the early days of web development, programmers used a lot of HTML and JavaScript code to develop web applications. However, this approach is difficult to maintain and manage because the HTML and JavaScript code can become very complex. To solve this problem, the Smarty template engine was created. Smarty is a template engine developed based on PHP for managing and generating W

Introduction to the usage of length function Introduction to the usage of length function Sep 19, 2023 am 11:41 AM

The length function is used to return the number of characters or bytes in a specified string. It can be used to calculate the length of a string for operation and judgment when querying and processing string data. It should be noted that the length function counts the number of characters in the string, not the number of bytes. For multibyte character sets, a character may consist of multiple bytes. Therefore, the length function counts multibyte characters as one character when calculating the string length.

See all articles