{assign var="bar_at" value=$product.supplier_reference|strpos:"="}
$product.supplier_reference
看起来像reference
我需要得到最后的“=”(实际引用)之后的内容。
上一次事件发生后如何获得strpos?
发布于 2017-08-02 11:39:04
首先,正确的函数是:strrpos
要做到这一点,您有多种方法:
1-纯粹的聪明方式:
{assign var="str" value="https://www.example.com/search?w=1366&h=610&q=the_actual_reference"}
{assign var="offset" value=$str|strrpos:"="}
{assign var="reference" value=$str|substr:($offset+1)}
{$reference}
2-在plugins目录中创建新插件,它位于以下路径下:vendor/smarty/smarty/libs/plugins/
,使用新插件名添加新文件,比如function.getReference.php
创建一个新函数smarty_function_getReference
然后编写您的纯PHP函数,然后从您的智能模板直接使用它,如下所示:
function smarty_function_money ($paramters) {
$url = $paramters['url'];
// here is our function body
}
在你聪明的模板里:
{getReference url="https://www.example.com/search?w=1366&h=610&q=the_actual_reference"}
3-增加新的修饰语:
无论什么地方-定义智能视图逻辑,注册新的修饰符:
$callback = function ($string) {
// perform your logic within this callback
};
$this->registerPlugin('modifier', 'getRefernce', $callback);
然后从智能模板直接调用这个修饰符,如下所示:
{"https://www.example.com/search?w=1366&h=610&q=the_actual_reference"|getRefernce}
https://stackoverflow.com/questions/45457678
复制相似问题